Commit Graph

48 Commits

Author SHA1 Message Date
João Moura
65e0d79195 pluralising root key when using arraySerializer 2015-06-15 15:59:01 -03:00
João Moura
1ea5608e78 updating tests to match new adapters structure 2015-06-15 13:39:36 -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
Santiago Pastorino
cbc7f114c0 Move generators test to it's own directory 2015-06-10 20:26:24 -03:00
Chris Branson
d34bba07b9 Ensure the adapters honor a custom root option and include meta when required 2015-06-04 17:33:41 +01: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
b6951809b0 Add test for required fields 2015-03-22 20:43:57 -04: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
Alexandre de Oliveira
3389218fd3 Merge pull request #725 from ggordon/has_one_support
Support has_one to be compatible with 0.8.x
2015-03-05 15:08:25 -08: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
Benjamin Fleischer
79653ac733 Replace has_one with attribute in template 2015-02-25 14:20:18 -06: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
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
Alexandre de Oliveira
971f501e55 Bugfix: include nested has_many association
Currently, doing `include: author.bio` would work correctly, but not for
has_many associations such as `include: author.roles`. This fixes it.

The problem was basically that we were not handling arrays for has_many linked,
as happens for ArraySerializers.
2014-11-11 14:35:00 -02:00
Gary Gordon
d97b2f5005 Fix infinite recursion
The method for testing whether to include an association was causing
an infinite loop when two models referenced each other.
2014-11-07 10:03:31 -05:00
Aaron Renoir
c9c58e31e5 merge upstream/master 2014-11-05 16:47:15 -08:00
Gary Gordon
d5bae0c2f0 Include 'linked' member for json-api collections
The options passed to the render are partitioned into adapter options
and serializer options. 'include' and 'root' are sent to the adapter,
not sure what options would go directly to serializer, but leaving this
in until I understand that better.
2014-11-03 17:13:55 -05: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
be54e0bc4f remove serializer dependency from fieldset 2014-10-27 15:24:19 -07: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
Jake Quain
c0166f3026 Check superclasses for Serializers 2014-10-13 17:39:54 -06: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
e45e5a82b7 Remove 'Adapter' suffix from adapters since they are in Adapter:: namespace 2014-08-29 11:40:56 +04:00
Tema Bolshakov
6496b08464 rename simple adapter to json 2014-08-29 11:01:39 +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
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
6cc4fa0258 * Configure adapter using ActiveModel::Serializer.config.adapter
* Get adapter instance using ActiveModel::Serializer::Adapter.adapter_for(serializer)
2014-08-27 09:05:28 +04:00
Tema Bolshakov
a54813806d Tests for ActiveModel::Serializer.serializer_for for not array serializer 2014-08-26 13:27:46 +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
c6eea916ad Move serializer tests into their own directory.
It'd be nice to keep some hygene here.
2014-07-09 16:19:02 -04:00