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
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
Nicolás Hock Isaza
1d7d9fd6aa
Fix nested include attributes
...
When the requests asked for a nested attribute in the `include` and it's
missing or empty, don't break because the type of the object can't be
determined.
If the request is for a collection and none of the elements has the
attribute, it will not be added to the `linked` key, similar to what
happens with simple includes.
2015-01-13 14:49:58 -05:00
Robbie Pitts
90023b1af7
Make linked resource type names consistent with root names
2015-01-11 14:24:01 -05: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
Alexandre de Oliveira
2f5626d616
Fixes nested has_many links in JSONAPI
...
When linked resource had has_many links, all of them would use the
association from the first resource, causing all of the items to build
`links` with the same associations.
This fixes it by iterating over the serializers, not just the
attributes array.
2014-11-13 16:38:47 -02: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
ac37570bff
Merge pull request #728 from rails-api/linked-resources-use-type-as-key
...
Use type as key for linked resources
2014-11-13 10:53:59 -02:00
Alexandre de Oliveira
4af02021ac
Merge pull request #703 from ggordon/specify_serializer_from_controller
...
Support serializer and each_serializer options in renderer
2014-11-12 20:09:51 -02:00
Alexandre de Oliveira
7333f20285
Use type as key for linked resources
...
If type is `author` but the association is called `writer`, the linked
resource key should be called `authors`, e.g
{
...
linked: {
authors: [{
...
}]
}
...
}
2014-11-12 20:03:25 -02:00
Alexandre de Oliveira
91b3fba509
Includes links inside of linked resources
...
According to
http://jsonapi.org/format/#document-structure-resource-objects ,
> Resource objects have the same internal structure, regardless of
> whether they represent primary or linked resources.
And then
http://jsonapi.org/format/#document-structure-resource-object-attributes ,
> There are four reserved keys in resource objects:
>
> "id"
> "type"
> "href"
> "links"
This commits includes `links` inside of linked resources.
2014-11-12 15:44:54 -02: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
Mike A. Owens
58b6c4a6b7
Allow for the implicit use of ArraySerializer when :each_serializer is specified.
2014-11-07 09:39:36 -05:00
Aaron Renoir
fc1562c04a
add fields to adapter initialize function, pull in master, add tests using includes with fields
2014-11-05 18:10:37 -08:00
Aaron Renoir
c9c58e31e5
merge upstream/master
2014-11-05 16:47:15 -08:00
Gary Gordon
c84430cdad
Support serializer and each_serializer in render json
2014-11-05 15:10:14 -05:00
Alexandre de Oliveira
95d122046d
Merge pull request #692 from ggordon/linked_for_jsonapi_collection
...
Include 'linked' member for json-api collections
2014-11-04 21:59:15 -02:00
Guillermo Iguaran
f5411f045f
Define as_json instead of to_json
2014-11-03 17:38:58 -05: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
3bba334cf8
JSON-API: Don't include linked section if associations are empty
2014-10-31 14:30:59 -05:00
Guillermo Iguaran
2d21a8e83f
Add type when association name is different than objects type
2014-10-31 01:54:13 -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
Alexandre de Oliveira
baf3db1365
Merge pull request #691 from jacob-s-son/fix-embed-option-for-associations
...
Fix embed option for associations
2014-10-29 18:41:59 -02: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
Edgars Jekabsons
f9b7c74235
Renamed embed test to have "test" suffix
...
Fixed reference to association options
2014-10-22 15:30:44 +03:00
Guillermo Iguaran
5f198667be
Fix support for custom root in JSON-API adapter
2014-10-22 04:01:12 -03:00
Guillermo Iguaran
7c030314cb
Serialize ids as strings in JSON-API adapter
2014-10-15 18:56:49 -05:00
Guillermo Iguaran
557b56a50e
Refactor adapters to implement support for array serialization
2014-10-15 17:35:50 -05:00
Guillermo Iguaran
3fa1116035
Include root by default in JSON-API serializers
2014-10-14 11:33:06 -05: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
410eacc30e
Merge pull request #677 from ride/embed-ids-option
...
Add support for embed: :ids option for in associations
2014-10-14 11:39:09 -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
Guillermo Iguaran
188336522f
Add support for embed: :ids option for in associations
2014-10-10 16:48:55 -05:00
Ryunosuke SATO
4fe9790bfa
Support Rails 4.2.0
...
This patch is the same fixes as #655 and #663 .
2014-10-10 00:52:59 +09: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 and Dmitry Myaskovskiy
ff37b6260d
test for json adapter
2014-08-29 19:40:01 +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
6bb4501f67
JsonApi adapter: serialize association
2014-08-29 11:37:27 +04:00
Tema Bolshakov
6496b08464
rename simple adapter to json
2014-08-29 11:01:39 +04:00
Tema Bolshakov
3dd4928279
* Do not ingerit array serializer from Serializer
...
* Tests for ArraySerializer
2014-08-29 10:58:14 +04:00
Tema Bolshakov
85ff8123fd
Include Enumerable to ArraySerializer
2014-08-28 23:03:28 +04:00
Tema Bolshakov
c1fdfc1cdc
First try to implement ArraySerializer
2014-08-28 19:16:24 +04:00
Tema Bolshakov
1b718b6d48
fix spelling
2014-08-28 18:56:22 +04:00
Tema Bolshakov
597765e3b0
start implementing json_api adapter to understand how associations should work
2014-08-28 18:55:27 +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
a6f9dae560
Concrete adapter should provide serializable hash for Adapter#to_json method
2014-08-27 09:33:14 +04:00
Tema Bolshakov
7b7d4d8907
Test for SimpleAdapter#serializable_hash
2014-08-27 09:15:07 +04:00
Tema Bolshakov
553c470e10
Serializer should be available wiithing adapter to inspect attributes and assotions
2014-08-27 09:09:01 +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
56725b45a6
Add NullAdapater
2014-08-27 08:41:45 +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
86fc7d7227
bump version to 0.10.0.pre
2014-08-22 17:02:05 -04:00
Steve Klabnik
886ada9151
don't hold on to serializer
...
this is an optimization for now, this may have to change later.
2014-07-09 23:05:41 -04: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
Steve Klabnik
4fc0f679df
Add generators.
...
This seemed like the easiest place to start.
2014-07-05 12:35:29 -04:00
Steve Klabnik
8a20377239
Set up gemspec, version, and .travis.yml
2014-07-05 00:56:57 -04:00
Steve Klabnik
c718915075
Generate a basic gem
2014-07-05 00:53:48 -04:00