Nicholas Shook
444b4cd1d8
all require
2015-09-17 14:06:55 -07:00
Nicholas Shook
faa56482d1
full require
2015-09-17 14:06:55 -07:00
Nicholas Shook
6bdb4a13e2
removed autoload statements
2015-09-17 14:06:54 -07:00
Nicholas Shook
a9e3143c19
add require statements to top of file
...
Based on
https://github.com/rails-api/active_model_serializers/issues/1170#issuecomment-141184047
2015-09-17 14:06:54 -07:00
Benjamin Fleischer
9d65f0adc5
Distinguish options ivar from local; Extract latent Adapter::CachedSerializer
2015-09-17 10:45:09 -05:00
Lucas Hosseini
ce7a839f3d
Extended format for JSONAPI include option.
2015-09-13 22:45:47 +02:00
Benjamin Fleischer
363345b8dd
Rename Adapter.get to Adapter.lookup
...
Per https://github.com/rails-api/active_model_serializers/pull/1017#discussion_r39003855
comment by sandstrom in discussion of the inherited hook
> I'm thinking that it would be better to register adapters manually, without using the hook, i.e.
> have people call ActiveModel::Serializer::Adapter.register directly (perhaps in an initializer).
> Possibly, some inspiration can be taken from how ActiveJob adapters are wired[1].
> [1] a11571cec3/activejob/lib/active_job/queue_adapter.rb (L52-L56)
2015-09-09 08:55:20 -05:00
Benjamin Fleischer
d9e76c29d5
Make Adapters registerable so they are not namespace-constrained
...
Changes:
- Introduce Adapter::get for use by Serializer.adapter
- Move Adapter-finding logic from Adapter::adapter_class into Adapter::get
Introduced interfaces:
- non-inherited methods
```ruby
ActiveModel::Serializer::Adapter.adapter_map # a Hash<adapter_name, adapter_class>
ActiveModel::Serializer::Adapter.adapters # an Array<adapter_name>
ActiveModel::Serializer::Adapter.register(name, klass) # adds an adapter to the adapter_map
ActiveModel::Serializer::Adapter.get(name_or_klass) # raises Argument error when adapter not found
```
- Automatically register adapters when subclassing
```ruby
def self.inherited(subclass)
ActiveModel::Serializer::Adapter.register(subclass.to_s.demodulize, subclass)
end
```
- Preserves subclass method `::adapter_class(adapter)`
```ruby
def self.adapter_class(adapter)
ActiveModel::Serializer::Adapter.get(adapter)
end
```
- Serializer.adapter now uses `Adapter.get(config.adapter)` rather than have duplicate logic
2015-09-08 22:59:36 -05:00
Bruno Bacarini
8634503849
Remove url options
...
Removing url options because It does not works at all.
Thus, there are others PR at the moment to include url(links) as well.
2015-09-07 12:13:19 -03:00
Lucas Hosseini
070a2e63bd
Merge remote-tracking branch 'upstream/master' into fix-jsonapi-ri
2015-09-06 17:21:43 +02:00
Benjamin Fleischer
228cc1c92a
Rubocop: Consistent spacing
2015-09-03 20:51:40 -05:00
Lucas Hosseini
8482abfac7
Move id and json_api_type methods from Serializer to JsonApi.
2015-08-31 02:32:38 +02:00
Lucas Hosseini
995bbcc18d
Fix definition of serializer attributes with multiple calls to attribute instead of one single call to attributes.
2015-08-28 21:06:10 +02:00
João Moura
64168cbecd
Merge pull request #1081 from beauby/jsonapi-singular-plural-config
...
Add configuration option to set resource type to singular/plural
2015-08-28 07:47:55 -03:00
Benjamin Fleischer
d315151e8a
Fix warnings
...
JRuby-specific: fix 'warning: (...) interpreted as grouped expression'
2015-08-26 09:22:02 -05:00
Lucas Hosseini
91235ba7bc
Add configuration option to set resource type to singular/plural with jsonapi.
2015-08-24 22:55:22 +02:00
Benjamin Fleischer
215fb85c7f
Test caller line parsing and digesting
2015-08-18 17:32:29 -04:00
Eric Guo
f93a7e8b41
need lookahead match for windows file path contain 'c:/git/'
...
So we will got full file path instead of only c if caller.first is: c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'
CALLER_FILE = /
/A # start of string
\S+ # one or more non-spaces
(?= # stop previous match when
:\d+:in # a colon is followed by one or more digits
# followed by a colon followed by in
)
/x
credit from https://gist.github.com/mikezter/540132 and @bf4
2015-08-18 09:52:34 +08:00
Mikhail Topolskiy
e8e4bdefd2
Use underscored json_root
2015-08-13 20:31:48 +03:00
Josh Lane
033ce8e88d
allow for a type attribute
...
* "namespace" json_api specific type method
2015-08-11 08:33:05 -07:00
Josh Lane
f6e3d4e1f9
allow id attribute to be overriden
2015-08-04 09:22:05 -07:00
Артём Большаков
2952a332e0
Associations refactoring
...
* Move all associations related code from Serializer class to Associations module
* Introduce Reflection class hierarchy
* Introduce Association class
* Rid off Serializer#each_association
* Introduce Serializer#associations enumerator
2015-07-30 11:20:29 +03:00
João Moura
418721302b
defining json_key(root) as model class name
2015-07-23 02:11:34 -04:00
Marek Pietrucha
e5ccb8e4dd
root option is working ( fixed #986 )
2015-07-16 15:32:09 -06:00
João Moura
775737619a
Merge pull request #996 from bf4/serializer_lint
...
Add linter for serializable resource
2015-07-13 19:37:39 -04:00
Benjamin Fleischer
28174e297d
Add linter for serializable resource
2015-07-09 11:20:19 -05:00
Rodrigo Ra
df63b59512
Add key option to serializer associations
2015-07-05 19:47:58 -03:00
João Moura
d3649d5b4e
Renaming Error to NoSerializerError
2015-06-26 02:16:35 -03:00
Benjamin Fleischer
e5d1e40dbd
Handle special-case of Array serializer with unserializable elements
2015-06-26 02:16:34 -03:00
Benjamin Fleischer
cf77786da2
Fix #955
2015-06-26 02:16:34 -03:00
João Moura
329691276a
disabling custom root option
2015-06-15 15:58:39 -03:00
João Moura
1c3a180a20
disable root as flag option
2015-06-13 15:48:33 -03:00
Lachlan Sylvester
97e82c3eb7
use model name to determine the type
2015-06-13 19:45:46 +10:00
João Moura
de23501995
Merge pull request #949 from edwardloveall/el-870-fix
...
Don't pass serializer option to associated serializers
2015-06-13 03:01:25 -03:00
João Moura
6251b90d25
Merge pull request #902 from cristianbica/serializer_file_digest
...
Added serializer file digest to the cache_key
2015-06-12 18:56:43 -03:00
Edward Loveall
0f0ef2baf5
Don't pass serializer option to associated serializers
...
Fixes #870
Commit af81a40 introduced passing a serializer's 'options'
along to its associated model serializers.
Thus, an explicit 'each_serializer' passed to render for a
singular resource would be passed on as the implicit 'serializer'
for its associations.
With @bf4
2015-06-10 18:20:34 -04:00
groyoh
5393e5d235
Prevent possible duplicated attributes
...
Calling ActiveModel::Serializer.attributes or ActiveModel::Serializer.attribute
methods multiple times won't create duplicated attributes anymore.
2015-05-18 22:42:10 +02:00
João Moura
d981ee5106
Merge pull request #880 from groyoh/serializer-inheritance
...
Inabling subclasses serializers to inherit attributes
2015-05-18 11:34:10 -03:00
Cristian Bica
7a62d31777
Added serializer file digest to the cache_key
...
Fixes #901
2015-05-06 08:37:18 +03:00
Bernard Potocki
c91b649504
Allow to define custom serializer for given class by defining #serializer_class method in serialized object's class. Resolves #515 .
2015-05-03 17:47:52 +02:00
Yohan Robert
02ffff599f
Serializers now inherit attributes
2015-04-23 13:25:36 +02:00
João Moura
792fb8a905
Adding Fragment Cache to AMS
...
It's an upgrade based on the new Cache implementation #693 .
It allows to use the Rails conventions to cache
specific attributes or associations.
It's based on the Cache Composition implementation.
2015-04-05 18:19:57 -03:00
Mateo Murphy
33f3a88ba0
Implement included and id and type as per spec
2015-03-22 20:43:56 -04:00
Guillermo Iguaran
b68d7f4826
Merge pull request #852 from mateomurphy/serializer-options-fix
...
Fix options merge order in `each_association`
2015-03-22 18:54:07 -05:00
Mateo Murphy
03372ea61d
Fix options merge order in each_association
...
Custom association serializers were getting clobbered when using an each serializer.
2015-03-20 00:22:46 -04:00
Mateo Murphy
ca985e1afd
Use association value for determining serializer used
...
Ensures overridden association value works when orignal association does not return a result.
2015-03-19 23:28:00 -04:00
Alexandre de Oliveira
0446a9714d
Merge pull request #833 from lsylvester/cache-serializers-for-class
...
Cache serializers for class
2015-03-13 19:55:49 -03:00
Alexandre de Oliveira
af81a403e3
Passes serializer options down into associations
2015-03-11 16:37:14 -03:00
Alexandre de Oliveira
48650ecf7e
Makes passed in options accessible inside serializers
...
In some cases, we want to pass arguments from the controller and we want
to serializer a resource according to that. This allows serializers to
use the `options` method to retrieve whatever was passed in via
arguments.
2015-03-11 14:53:57 -03:00
Lachlan Sylvester
980d1ced81
add explicit thread_safe dependency
2015-03-11 11:15:17 +11:00
lsylvester
2b0c5ee084
clear the cache between requests
2015-03-11 09:53:47 +11:00
lsylvester
3fb560908e
cache the serializers for a class
2015-03-11 09:53:47 +11:00
Guillermo Iguaran
d55f3b33b4
Merge pull request #811 from mateomurphy/scope
...
Reimplement serialization scope and scope_name
2015-03-10 10:16:06 -05:00
Gary Gordon
651b99f22e
Support has_one to be compatible with 0.8.x
...
Update README and CHANGELOG
2015-03-01 13:47:34 -05:00
Will Jordan
f2ee544a88
Fix explicit serializer for associations
2015-02-24 16:01:43 -08:00
Mateo Murphy
2962f3f64e
Reimplement serialization scope and scope_name
2015-02-09 11:24:41 -05:00
Joao Moura
8a432ad2b3
Adding cache support to version 0.10.0
...
It's a new implementation of cache based on ActiveSupport::Cache.
The implementation abstracts the cache in Adapter class on a
private method called cached_object, this method is intended
to be used on Adapters inside serializable_hash method in order
to cache each instance of the object that will be returned by
the serializer.
Some of its features are:
- A different syntax. (no longer need the cache_key method).
- An options argument that have the same arguments of ActiveSupport::Cache::Store, plus a key option that will be the prefix of the object cache on a pattern "#{key}-#{object.id}".
- It cache the objects individually and not the whole Serializer return, re-using it in different requests (as a show and a index method for example.)
2015-02-02 14:53:34 -02:00
Alexandre de Oliveira
e47231cdc8
Support overriding association methods
...
You can override associations to define custom scope on them.
2015-01-29 16:52:18 -02:00
Alexandre de Oliveira
6eb75af96b
Merge pull request #696 from ggordon/explicit_serializer
...
Explicitly set serializer for associations
2015-01-06 09:57:07 -02:00
Alexandre de Oliveira
87f817943a
Merge pull request #700 from arenoir/sparse_fieldsets
...
sparse fieldsets
2015-01-06 09:38:51 -02:00
Alexandre de Oliveira
bd27da1b76
Adds support for meta attribute
...
Currently, 0.10.0.pre doesn't support `meta` option in `render`. This
way, there's no way to support features such as pagination. `0.9` had
this feature in place.
This adds support for it, as well as fixes small things in README.md.
This won't support `meta` in array responses because arrays don't have
keys, obviously. Also, the response should have a `root` key, otherwise
no `meta` will be included.
In some cases, for example using JsonApi, ArraySerializer will result in
a response with a `root`. In that case, `meta` will be included.
2015-01-05 02:56:33 -02:00
Joakim Ekström
9768da7a70
Missing a word
2014-12-04 17:05:10 +01:00
Aaron Renoir
2ed52f96a6
merge upstream update fieldset
2014-11-13 17:45:47 -08:00
Gary Gordon
5560b49098
Allow overriding the adapter with render option
...
Make it easy to use multiple adapters in an app.
use "adapter: false" to not use ams
make a test override config.adapter
2014-11-13 10:23:19 -05:00
Gary Gordon
9f9715801a
Explicitly set serializer for associations
...
Document specifying serializer for assocaition
2014-11-13 10:17:59 -05:00
Gary Gordon
08716d20c9
Rename attribute with :key (0.8.x compatibility)
2014-11-13 08:03:22 -05:00
Aaron Renoir
c9c58e31e5
merge upstream/master
2014-11-05 16:47:15 -08:00
Guillermo Iguaran
19ac139880
Handle correctly null associations
...
null belongs_to associations are now serialized as nil instead
of raise an error during serialization.
2014-10-30 09:35:05 -05:00
Aaron Renoir
39bee48ae6
implement sparse fieldsets http://jsonapi.org/format/#fetching-sparse-fieldsets
2014-10-26 13:04:14 -07:00
Steve Klabnik
099f773a65
Merge pull request #625 from JordanFaust/feature/url-dsl
...
Add DSL for urls
2014-10-14 11:47:14 -04:00
Steve Klabnik
341cca7d8a
Merge pull request #681 from quainjn/inherited-serializer
...
Check superclasses for Serializers
2014-10-14 11:36:02 -04:00
Jake Quain
c0166f3026
Check superclasses for Serializers
2014-10-13 17:39:54 -06:00
NullVoxPopuli
7338b62b02
add support for root keys
...
remove debugging gem
fix white space
2014-10-13 13:27:09 -04:00
Jordan Faust
ad0859e262
Add DSL for urls
2014-09-01 13:44:22 -05:00
Tema Bolshakov and Dmitry Myaskovskiy
71a43a432a
Pass options to associations
2014-08-29 20:16:11 +04:00
Tema Bolshakov and Dmitry Myaskovskiy
258b5953e2
clean up code
2014-08-29 19:47:46 +04:00
Tema Bolshakov and Dmitry Myaskovskiy
45a47a1c4d
safe_constantize instead of rescue
2014-08-29 19:47:29 +04:00
Tema Bolshakov
77847d7c02
User String#constantize instead of Object.const_get
2014-08-29 13:48:06 +04:00
Tema Bolshakov
139609355f
Object.const_get differs on 2.0 and 2.1.2. So rescue from NameError
2014-08-29 13:01:01 +04:00
Tema Bolshakov
b4a313e6d8
Merge remote-tracking branch 'upstream/master' into feature/adapter
2014-08-29 12:55:20 +04:00
Tema Bolshakov
e45e5a82b7
Remove 'Adapter' suffix from adapters since they are in Adapter:: namespace
2014-08-29 11:40:56 +04:00
Tema Bolshakov
c1fdfc1cdc
First try to implement ArraySerializer
2014-08-28 19:16:24 +04:00
Tema Bolshakov
466c7d5dd8
Wrap association into Serializers
2014-08-28 18:46:19 +04:00
Tony Pitale
dee2f1969e
Rails does not support const_defined? in development mode;
...
Use const_get instead, and rescue NameError
2014-08-27 14:42:41 -04:00
Tema Bolshakov
fa4ee9d645
Add Serializer#associations
2014-08-27 11:21:01 +04:00
Tema Bolshakov
b1f7a5ccda
Move Adapter.adapter_for to Serializer.adapter
2014-08-27 11:02:39 +04:00
Tema Bolshakov
f00fe5595d
* Rename NullAdapter to SimpleAdapter
...
* Introduce abstract Adapter class
* Organaze test structure to match convemtions
2014-08-27 08:21:08 +04:00
Tema Bolshakov
d39a3e0aec
serializer_for Array
2014-08-26 12:50:47 +04:00
Jordan Faust
00f7cab864
Add DSL for assocations
2014-08-23 15:20:48 -05:00
Steve Klabnik
970b542549
Implement basic rendering
...
Woo actioncontroller
2014-07-09 17:52:31 -04:00
Steve Klabnik
1ea83c8bee
Implement a NullAdapter.
...
This adapter basically doesn't do anything, and just serializes
the attributes into plain old JSON.
2014-07-09 16:51:30 -04:00
Steve Klabnik
729a823868
Getting started: attributes.
...
Super super basic collection of attributes. Nothing fancy.
2014-07-09 16:16:39 -04:00