active_model_serializers 0.10.6 → 0.10.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +102 -1
- data/README.md +21 -23
- data/lib/action_controller/serialization.rb +11 -1
- data/lib/active_model/serializable_resource.rb +2 -0
- data/lib/active_model/serializer.rb +35 -19
- data/lib/active_model/serializer/adapter.rb +2 -0
- data/lib/active_model/serializer/adapter/attributes.rb +2 -0
- data/lib/active_model/serializer/adapter/base.rb +2 -0
- data/lib/active_model/serializer/adapter/json.rb +2 -0
- data/lib/active_model/serializer/adapter/json_api.rb +2 -0
- data/lib/active_model/serializer/adapter/null.rb +2 -0
- data/lib/active_model/serializer/array_serializer.rb +2 -0
- data/lib/active_model/serializer/association.rb +2 -0
- data/lib/active_model/serializer/attribute.rb +2 -0
- data/lib/active_model/serializer/belongs_to_reflection.rb +2 -0
- data/lib/active_model/serializer/collection_serializer.rb +8 -5
- data/lib/active_model/serializer/concerns/caching.rb +7 -2
- data/lib/active_model/serializer/error_serializer.rb +2 -0
- data/lib/active_model/serializer/errors_serializer.rb +2 -0
- data/lib/active_model/serializer/field.rb +2 -0
- data/lib/active_model/serializer/fieldset.rb +3 -1
- data/lib/active_model/serializer/has_many_reflection.rb +2 -0
- data/lib/active_model/serializer/has_one_reflection.rb +2 -0
- data/lib/active_model/serializer/lazy_association.rb +6 -2
- data/lib/active_model/serializer/link.rb +23 -0
- data/lib/active_model/serializer/lint.rb +2 -0
- data/lib/active_model/serializer/null.rb +2 -0
- data/lib/active_model/serializer/reflection.rb +10 -5
- data/lib/active_model/serializer/version.rb +3 -1
- data/lib/active_model_serializers.rb +21 -11
- data/lib/active_model_serializers/adapter.rb +3 -1
- data/lib/active_model_serializers/adapter/attributes.rb +23 -0
- data/lib/active_model_serializers/adapter/base.rb +2 -0
- data/lib/active_model_serializers/adapter/json.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api.rb +14 -9
- data/lib/active_model_serializers/adapter/json_api/deserialization.rb +3 -1
- data/lib/active_model_serializers/adapter/json_api/error.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/jsonapi.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/link.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/meta.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +42 -21
- data/lib/active_model_serializers/adapter/json_api/relationship.rb +18 -4
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +33 -25
- data/lib/active_model_serializers/adapter/null.rb +2 -0
- data/lib/active_model_serializers/callbacks.rb +2 -0
- data/lib/active_model_serializers/deprecate.rb +2 -0
- data/lib/active_model_serializers/deserialization.rb +2 -0
- data/lib/active_model_serializers/json_pointer.rb +2 -0
- data/lib/active_model_serializers/logging.rb +2 -0
- data/lib/active_model_serializers/lookup_chain.rb +2 -0
- data/lib/active_model_serializers/model.rb +2 -0
- data/lib/active_model_serializers/model/caching.rb +25 -0
- data/lib/active_model_serializers/railtie.rb +4 -0
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +2 -0
- data/lib/active_model_serializers/serializable_resource.rb +4 -2
- data/lib/active_model_serializers/serialization_context.rb +2 -0
- data/lib/active_model_serializers/test.rb +2 -0
- data/lib/active_model_serializers/test/schema.rb +2 -0
- data/lib/active_model_serializers/test/serializer.rb +2 -0
- data/lib/generators/rails/resource_override.rb +2 -0
- data/lib/generators/rails/serializer_generator.rb +2 -0
- data/lib/grape/active_model_serializers.rb +2 -0
- data/lib/grape/formatters/active_model_serializers.rb +2 -0
- data/lib/grape/helpers/active_model_serializers.rb +2 -0
- data/lib/tasks/rubocop.rake +2 -0
- metadata +47 -276
- data/.github/ISSUE_TEMPLATE.md +0 -29
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
- data/.gitignore +0 -35
- data/.rubocop.yml +0 -105
- data/.simplecov +0 -110
- data/.travis.yml +0 -55
- data/CODE_OF_CONDUCT.md +0 -74
- data/CONTRIBUTING.md +0 -105
- data/Gemfile +0 -56
- data/Rakefile +0 -74
- data/active_model_serializers.gemspec +0 -63
- data/appveyor.yml +0 -30
- data/bin/bench +0 -171
- data/bin/bench_regression +0 -316
- data/bin/rubocop +0 -38
- data/bin/serve_benchmark +0 -39
- data/docs/README.md +0 -41
- data/docs/STYLE.md +0 -58
- data/docs/general/adapters.md +0 -263
- data/docs/general/caching.md +0 -58
- data/docs/general/configuration_options.md +0 -169
- data/docs/general/deserialization.md +0 -100
- data/docs/general/fields.md +0 -31
- data/docs/general/getting_started.md +0 -133
- data/docs/general/instrumentation.md +0 -40
- data/docs/general/key_transforms.md +0 -40
- data/docs/general/logging.md +0 -21
- data/docs/general/rendering.md +0 -293
- data/docs/general/serializers.md +0 -480
- data/docs/how-open-source-maintained.jpg +0 -0
- data/docs/howto/add_pagination_links.md +0 -138
- data/docs/howto/add_relationship_links.md +0 -140
- data/docs/howto/add_root_key.md +0 -55
- data/docs/howto/grape_integration.md +0 -42
- data/docs/howto/outside_controller_use.md +0 -66
- data/docs/howto/passing_arbitrary_options.md +0 -27
- data/docs/howto/serialize_poro.md +0 -73
- data/docs/howto/test.md +0 -154
- data/docs/howto/upgrade_from_0_8_to_0_10.md +0 -265
- data/docs/integrations/ember-and-json-api.md +0 -147
- data/docs/integrations/grape.md +0 -19
- data/docs/jsonapi/errors.md +0 -56
- data/docs/jsonapi/schema.md +0 -151
- data/docs/jsonapi/schema/schema.json +0 -366
- data/docs/rfcs/0000-namespace.md +0 -106
- data/docs/rfcs/template.md +0 -15
- data/test/action_controller/adapter_selector_test.rb +0 -62
- data/test/action_controller/explicit_serializer_test.rb +0 -135
- data/test/action_controller/json/include_test.rb +0 -246
- data/test/action_controller/json_api/deserialization_test.rb +0 -112
- data/test/action_controller/json_api/errors_test.rb +0 -40
- data/test/action_controller/json_api/fields_test.rb +0 -66
- data/test/action_controller/json_api/linked_test.rb +0 -202
- data/test/action_controller/json_api/pagination_test.rb +0 -116
- data/test/action_controller/json_api/transform_test.rb +0 -189
- data/test/action_controller/lookup_proc_test.rb +0 -49
- data/test/action_controller/namespace_lookup_test.rb +0 -232
- data/test/action_controller/serialization_scope_name_test.rb +0 -235
- data/test/action_controller/serialization_test.rb +0 -472
- data/test/active_model_serializers/adapter_for_test.rb +0 -208
- data/test/active_model_serializers/json_pointer_test.rb +0 -22
- data/test/active_model_serializers/logging_test.rb +0 -77
- data/test/active_model_serializers/model_test.rb +0 -142
- data/test/active_model_serializers/railtie_test_isolated.rb +0 -68
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +0 -161
- data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -71
- data/test/active_model_serializers/test/schema_test.rb +0 -131
- data/test/active_model_serializers/test/serializer_test.rb +0 -62
- data/test/active_record_test.rb +0 -9
- data/test/adapter/attributes_test.rb +0 -40
- data/test/adapter/deprecation_test.rb +0 -100
- data/test/adapter/json/belongs_to_test.rb +0 -45
- data/test/adapter/json/collection_test.rb +0 -104
- data/test/adapter/json/has_many_test.rb +0 -53
- data/test/adapter/json/transform_test.rb +0 -93
- data/test/adapter/json_api/belongs_to_test.rb +0 -155
- data/test/adapter/json_api/collection_test.rb +0 -96
- data/test/adapter/json_api/errors_test.rb +0 -76
- data/test/adapter/json_api/fields_test.rb +0 -96
- data/test/adapter/json_api/has_many_embed_ids_test.rb +0 -43
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -96
- data/test/adapter/json_api/has_many_test.rb +0 -173
- data/test/adapter/json_api/has_one_test.rb +0 -80
- data/test/adapter/json_api/include_data_if_sideloaded_test.rb +0 -183
- data/test/adapter/json_api/json_api_test.rb +0 -33
- data/test/adapter/json_api/linked_test.rb +0 -413
- data/test/adapter/json_api/links_test.rb +0 -95
- data/test/adapter/json_api/pagination_links_test.rb +0 -193
- data/test/adapter/json_api/parse_test.rb +0 -137
- data/test/adapter/json_api/relationship_test.rb +0 -397
- data/test/adapter/json_api/resource_identifier_test.rb +0 -110
- data/test/adapter/json_api/resource_meta_test.rb +0 -100
- data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -82
- data/test/adapter/json_api/transform_test.rb +0 -512
- data/test/adapter/json_api/type_test.rb +0 -61
- data/test/adapter/json_test.rb +0 -46
- data/test/adapter/null_test.rb +0 -22
- data/test/adapter/polymorphic_test.rb +0 -171
- data/test/adapter_test.rb +0 -67
- data/test/array_serializer_test.rb +0 -22
- data/test/benchmark/app.rb +0 -65
- data/test/benchmark/benchmarking_support.rb +0 -67
- data/test/benchmark/bm_active_record.rb +0 -81
- data/test/benchmark/bm_adapter.rb +0 -38
- data/test/benchmark/bm_caching.rb +0 -119
- data/test/benchmark/bm_lookup_chain.rb +0 -83
- data/test/benchmark/bm_transform.rb +0 -45
- data/test/benchmark/config.ru +0 -3
- data/test/benchmark/controllers.rb +0 -83
- data/test/benchmark/fixtures.rb +0 -219
- data/test/cache_test.rb +0 -651
- data/test/collection_serializer_test.rb +0 -123
- data/test/fixtures/active_record.rb +0 -113
- data/test/fixtures/poro.rb +0 -225
- data/test/generators/scaffold_controller_generator_test.rb +0 -24
- data/test/generators/serializer_generator_test.rb +0 -75
- data/test/grape_test.rb +0 -196
- data/test/lint_test.rb +0 -49
- data/test/logger_test.rb +0 -20
- data/test/poro_test.rb +0 -9
- data/test/serializable_resource_test.rb +0 -79
- data/test/serializers/association_macros_test.rb +0 -37
- data/test/serializers/associations_test.rb +0 -424
- data/test/serializers/attribute_test.rb +0 -153
- data/test/serializers/attributes_test.rb +0 -52
- data/test/serializers/caching_configuration_test_isolated.rb +0 -170
- data/test/serializers/configuration_test.rb +0 -32
- data/test/serializers/fieldset_test.rb +0 -14
- data/test/serializers/meta_test.rb +0 -202
- data/test/serializers/options_test.rb +0 -32
- data/test/serializers/read_attribute_for_serialization_test.rb +0 -79
- data/test/serializers/reflection_test.rb +0 -427
- data/test/serializers/root_test.rb +0 -21
- data/test/serializers/serialization_test.rb +0 -55
- data/test/serializers/serializer_for_test.rb +0 -136
- data/test/serializers/serializer_for_with_namespace_test.rb +0 -88
- data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
- data/test/support/isolated_unit.rb +0 -82
- data/test/support/rails5_shims.rb +0 -53
- data/test/support/rails_app.rb +0 -38
- data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
- data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
- data/test/support/schemas/custom/show.json +0 -7
- data/test/support/schemas/hyper_schema.json +0 -93
- data/test/support/schemas/render_using_json_api.json +0 -43
- data/test/support/schemas/simple_json_pointers.json +0 -10
- data/test/support/serialization_testing.rb +0 -71
- data/test/test_helper.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4efe10f8c12914205c5d3a42c5cac29bdd2d01faea644c67606e0f24fc49ab3
|
4
|
+
data.tar.gz: 9751dfae561915e17ba3d15fa6caf5b0eb2e708c672db64b54aaa5d3f0f8d0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc6dad9d1b4e3d7fec54bdbf38f70b39d8ed85373a267639996778f02508be82bf19e81b4acecb7d4161939de74da56e45025292cfd06c12a1b35580e283feb
|
7
|
+
data.tar.gz: eeab962f26dea765ea293975744695900654f07e7a001c592f8b748862935f60df12e9f9689166d8babb929fdeb4ca0d060ab0537dcf1b3cbfa8cb5f8b4cbd71
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## 0.10.x
|
2
2
|
|
3
|
-
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.
|
3
|
+
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.11...0-10-stable)
|
4
4
|
|
5
5
|
Breaking changes:
|
6
6
|
|
@@ -10,6 +10,107 @@ Fixes:
|
|
10
10
|
|
11
11
|
Misc:
|
12
12
|
|
13
|
+
### [v0.10.11 (2020-12-04)](https://github.com/rails-api/active_model_serializers/compare/v0.10.10...v0.10.11)
|
14
|
+
|
15
|
+
Features:
|
16
|
+
|
17
|
+
- [#2361](https://github.com/rails-api/active_model_serializers/pull/2361) Add `ActiveModelSerializers.config.use_sha1_digests` to allow customization of the hashing algorithm used for serializer caching (@alexzherdev)
|
18
|
+
|
19
|
+
Fixes:
|
20
|
+
|
21
|
+
- [#2344](https://github.com/rails-api/active_model_serializers/pull/2344) Fixes #2341 introduced since #2223 (@wasifhossain)
|
22
|
+
- [#2395](https://github.com/rails-api/active_model_serializers/pull/2395) remove explicit require for thread_safe (@ritikesh)
|
23
|
+
|
24
|
+
### [v0.10.10 (2019-07-13)](https://github.com/rails-api/active_model_serializers/compare/v0.10.9...v0.10.10)
|
25
|
+
|
26
|
+
Fixes:
|
27
|
+
|
28
|
+
- [#2319](https://github.com/rails-api/active_model_serializers/pull/2319) Fixes #2316. (@kylekeesling)
|
29
|
+
- Fix Rails 6.0 deprication warnings
|
30
|
+
- update test fixture schema to use `timestamps` instead of `timestamp`
|
31
|
+
- [#2223](https://github.com/rails-api/active_model_serializers/pull/2223) Support Fieldset in Attributes/JSON adapters documented in [docs/general/fields.md](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/fields.md) that worked partially before (@bf4)
|
32
|
+
- [#2337](https://github.com/rails-api/active_model_serializers/pull/2337) fix incorrect belongs_to serialization when foreign_key on object and belongs_to is blank (@InteNs)
|
33
|
+
- Fixes incorrect json-api generation when `jsonapi_use_foreign_key_on_belongs_to_relationship` is `true` and the relationship is blank
|
34
|
+
- [#2172](https://github.com/rails-api/active_model_serializers/pull/2172) Preserve the namespace when falling back to a superclass serializer
|
35
|
+
|
36
|
+
Misc:
|
37
|
+
|
38
|
+
- [#2327](https://github.com/rails-api/active_model_serializers/pull/2327) Add support for Ruby 2.6 on Travis CI (@wasifhossain)
|
39
|
+
- [#2304](https://github.com/rails-api/active_model_serializers/pull/2304) Slim down bundled gem by excluding test files and docs (@greysteil)
|
40
|
+
|
41
|
+
### [v0.10.9 (2019-02-08)](https://github.com/rails-api/active_model_serializers/compare/v0.10.8...v0.10.9)
|
42
|
+
|
43
|
+
Fixes:
|
44
|
+
|
45
|
+
- [#2288](https://github.com/rails-api/active_model_serializers/pull/2288)
|
46
|
+
Change the fetch method to deal with recyclable key cache strategy.
|
47
|
+
Fixes #2287. (@cintamani, @wasifhossain)
|
48
|
+
- [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated.
|
49
|
+
|
50
|
+
Misc:
|
51
|
+
|
52
|
+
- [#2309](https://github.com/rails-api/active_model_serializers/pull/2309) Performance and memory usage fixes
|
53
|
+
|
54
|
+
### [v0.10.8 (2018-11-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.7...v0.10.8)
|
55
|
+
|
56
|
+
Features:
|
57
|
+
- [#2279](https://github.com/rails-api/active_model_serializers/pull/2279) Support condition options in serializer link statements
|
58
|
+
|
59
|
+
Fixes:
|
60
|
+
|
61
|
+
- [#2296](https://github.com/rails-api/active_model_serializers/pull/2296) Fixes #2295 (@Hirurg103)
|
62
|
+
- Fix finding of namespaced serializer and non-namespaced model.
|
63
|
+
- [#2289](https://github.com/rails-api/active_model_serializers/pull/2289) Fixes #2255 (@f-mer)
|
64
|
+
- Fix autoloading race condition, especially in Rails 5.
|
65
|
+
- [#2299](https://github.com/rails-api/active_model_serializers/pull/2299) Fixes #2270 (@chau-bao-long via #2276)
|
66
|
+
- Fix reflection thread-safety bug
|
67
|
+
|
68
|
+
### [v0.10.7 (2017-11-14)](https://github.com/rails-api/active_model_serializers/compare/v0.10.6...v0.10.7)
|
69
|
+
|
70
|
+
Regressions Fixed From v0.10.6:
|
71
|
+
|
72
|
+
- [#2211](https://github.com/rails-api/active_model_serializers/pull/2211). Fixes #2125, #2160. (@bf4)
|
73
|
+
- Fix polymorphic belongs_to tests; passes on v0.10.5, fails on v0.10.6
|
74
|
+
- Fix JSON:API polymorphic type regression from v0.10.5
|
75
|
+
- Fix JSON:API: for_type_and_id should always inflect_type
|
76
|
+
```
|
77
|
+
Should Serializer._type ever be inflected?
|
78
|
+
Right now, it won't be, but association.serializer._type will be inflected.
|
79
|
+
|
80
|
+
That's the current behavior.
|
81
|
+
```
|
82
|
+
- [#2216](https://github.com/rails-api/active_model_serializers/pull/2216). Fixes #2132, #2180. (@bf4)
|
83
|
+
- Fix JSON:API: Serialize resource type for unpersisted records (blank id)
|
84
|
+
- [#2218](https://github.com/rails-api/active_model_serializers/pull/2218). Fixes #2178. (@bf4)
|
85
|
+
- Fix JSON:API: Make using foreign key on belongs_to opt-in. No effect on polymorphic relationships.
|
86
|
+
```
|
87
|
+
# set to true to opt-in
|
88
|
+
ActiveModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
|
89
|
+
```
|
90
|
+
|
91
|
+
Features:
|
92
|
+
|
93
|
+
- [#2136](https://github.com/rails-api/active_model_serializers/pull/2136) Enable inclusion of sideloaded relationship objects by `key`. (@caomania)
|
94
|
+
- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) ActiveModelSerializers::Model#attributes. Originally in [#1982](https://github.com/rails-api/active_model_serializers/pull/1982). (@bf4)
|
95
|
+
- [#2130](https://github.com/rails-api/active_model_serializers/pull/2130) Allow serialized ID to be overwritten for belongs-to relationships. (@greysteil)
|
96
|
+
- [#2189](https://github.com/rails-api/active_model_serializers/pull/2189)
|
97
|
+
Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.3']`
|
98
|
+
(@tagliala)
|
99
|
+
|
100
|
+
Fixes:
|
101
|
+
|
102
|
+
- [#2022](https://github.com/rails-api/active_model_serializers/pull/2022) Mutation of ActiveModelSerializers::Model now changes the attributes. Originally in [#1984](https://github.com/rails-api/active_model_serializers/pull/1984). (@bf4)
|
103
|
+
- [#2200](https://github.com/rails-api/active_model_serializers/pull/2200) Fix deserialization of polymorphic relationships. (@dennis95stumm)
|
104
|
+
- [#2214](https://github.com/rails-api/active_model_serializers/pull/2214) Fail if unable to infer collection type with json adapter. (@jmeredith16)
|
105
|
+
- [#2149](https://github.com/rails-api/active_model_serializers/pull/2149) Always include self, first, last pagination link. (@mecampbellsoup)
|
106
|
+
- [#2179](https://github.com/rails-api/active_model_serializers/pull/2179) Fixes #2173, Pass block to Enumerator.new. (@drn)
|
107
|
+
|
108
|
+
Misc:
|
109
|
+
|
110
|
+
- [#2176](https://github.com/rails-api/active_model_serializers/pull/2176) Documentation for global adapter config. (@mrpinsky)
|
111
|
+
- [#2215](https://github.com/rails-api/active_model_serializers/pull/2215) Update `serializers.md` documentation to denote alternate use cases for `scope`. (@stratigos)
|
112
|
+
- [#2212](https://github.com/rails-api/active_model_serializers/pull/2212) Remove legacy has_many_embed_ids test. (@bf4)
|
113
|
+
|
13
114
|
### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6)
|
14
115
|
|
15
116
|
Fixes:
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
<tr>
|
5
5
|
<td>Build Status</td>
|
6
6
|
<td>
|
7
|
-
<a href="https://travis-ci.org/rails-api/active_model_serializers"><img src="https://travis-ci.org/rails-api/active_model_serializers.svg?branch=
|
8
|
-
<a href="https://ci.appveyor.com/project/
|
7
|
+
<a href="https://travis-ci.org/rails-api/active_model_serializers"><img src="https://api.travis-ci.org/rails-api/active_model_serializers.svg?branch=0-10-stable" alt="Build Status" ></a>
|
8
|
+
<a href="https://ci.appveyor.com/project/bf4/active-model-serializers/branch/0-10-stable"><img src="https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true" alt="Build status"></a>
|
9
9
|
</td>
|
10
10
|
</tr>
|
11
11
|
<tr>
|
@@ -41,7 +41,7 @@ these methods to the adapter.)
|
|
41
41
|
|
42
42
|
By default ActiveModelSerializers will use the **Attributes Adapter** (no JSON root).
|
43
43
|
But we strongly advise you to use **JsonApi Adapter**, which
|
44
|
-
follows 1.0 of the format specified in [jsonapi.org/format](
|
44
|
+
follows 1.0 of the format specified in [jsonapi.org/format](https://jsonapi.org/format).
|
45
45
|
Check how to change the adapter in the sections below.
|
46
46
|
|
47
47
|
`0.10.x` is **not** backward compatible with `0.9.x` nor `0.8.x`.
|
@@ -49,8 +49,6 @@ Check how to change the adapter in the sections below.
|
|
49
49
|
`0.10.x` is based on the `0.8.0` code, but with a more flexible
|
50
50
|
architecture. We'd love your help. [Learn how you can help here.](CONTRIBUTING.md)
|
51
51
|
|
52
|
-
It is generally safe and recommended to use the master branch.
|
53
|
-
|
54
52
|
## Installation
|
55
53
|
|
56
54
|
Add this line to your application's Gemfile:
|
@@ -77,9 +75,9 @@ More information is available in the [Guides](docs) and
|
|
77
75
|
If you find a bug, please report an [Issue](https://github.com/rails-api/active_model_serializers/issues/new)
|
78
76
|
and see our [contributing guide](CONTRIBUTING.md).
|
79
77
|
|
80
|
-
If you have a question, please [post to Stack Overflow](
|
78
|
+
If you have a question, please [post to Stack Overflow](https://stackoverflow.com/questions/tagged/active-model-serializers).
|
81
79
|
|
82
|
-
If you'd like to chat, we have a [community slack](
|
80
|
+
If you'd like to chat, we have a [community slack](https://amserializers.herokuapp.com).
|
83
81
|
|
84
82
|
Thanks!
|
85
83
|
|
@@ -89,14 +87,14 @@ If you're reading this at https://github.com/rails-api/active_model_serializers
|
|
89
87
|
reading documentation for our `master`, which may include features that have not
|
90
88
|
been released yet. Please see below for the documentation relevant to you.
|
91
89
|
|
92
|
-
- [0.10 (
|
93
|
-
- [0.10.
|
94
|
-
|
95
|
-
|
90
|
+
- [0.10 (0-10-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-10-stable)
|
91
|
+
- [0.10.10 (latest release) Documentation](https://github.com/rails-api/active_model_serializers/tree/v0.10.10)
|
92
|
+
- [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.10.10)
|
93
|
+
- [Guides](docs)
|
96
94
|
- [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
|
97
|
-
|
95
|
+
- [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.9.7)
|
98
96
|
- [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
|
99
|
-
|
97
|
+
- [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.8.4)
|
100
98
|
|
101
99
|
|
102
100
|
## High-level behavior
|
@@ -173,12 +171,12 @@ The original design is also available [here](https://github.com/rails-api/active
|
|
173
171
|
|
174
172
|
### ActiveModel::Serializer
|
175
173
|
|
176
|
-
An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/
|
174
|
+
An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb)
|
177
175
|
and exposes an `attributes` method, among a few others.
|
178
176
|
It allows you to specify which attributes and associations should be represented in the serializatation of the resource.
|
179
177
|
It requires an adapter to transform its attributes into a JSON document; it cannot be serialized itself.
|
180
178
|
It may be useful to think of it as a
|
181
|
-
[presenter](
|
179
|
+
[presenter](https://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
|
182
180
|
|
183
181
|
#### ActiveModel::CollectionSerializer
|
184
182
|
|
@@ -187,10 +185,10 @@ and, if there is no serializer, primitives.
|
|
187
185
|
|
188
186
|
### ActiveModelSerializers::Adapter::Base
|
189
187
|
|
190
|
-
The **`
|
188
|
+
The **`ActiveModelSerializers::Adapter::Base`** describes the structure of the JSON document generated from a
|
191
189
|
serializer. For example, the `Attributes` example represents each serializer as its
|
192
190
|
unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
|
193
|
-
API](
|
191
|
+
API](https://jsonapi.org/) document.
|
194
192
|
|
195
193
|
### ActiveModelSerializers::SerializableResource
|
196
194
|
|
@@ -231,7 +229,7 @@ High-level overview:
|
|
231
229
|
- `:each_serializer` specifies the serializer for each resource in the collection.
|
232
230
|
- For a **single resource**, the `:serializer` option is the resource serializer.
|
233
231
|
- Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
|
234
|
-
[`ADAPTER_OPTION_KEYS`](
|
232
|
+
[`ADAPTER_OPTION_KEYS`](lib/active_model_serializers/serializable_resource.rb#L5).
|
235
233
|
The remaining options are serializer options.
|
236
234
|
|
237
235
|
Details:
|
@@ -256,7 +254,7 @@ Details:
|
|
256
254
|
2. `adapter_instance = ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)`
|
257
255
|
1. **ActiveModel::Serializer::CollectionSerializer#new**
|
258
256
|
1. If the `serializer_instance` was a `CollectionSerializer` and the `:serializer` serializer_opts
|
259
|
-
is present, then [that serializer is passed into each resource](https://github.com/rails-api/active_model_serializers/blob/
|
257
|
+
is present, then [that serializer is passed into each resource](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/lib/active_model/serializer/collection_serializer.rb#L77-L79).
|
260
258
|
1. **ActiveModel::Serializer#attributes** is used by the adapter to get the attributes for
|
261
259
|
resource as defined by the serializer.
|
262
260
|
|
@@ -268,11 +266,11 @@ to know about, but not part of ActiveModelSerializers.)
|
|
268
266
|
|
269
267
|
- An `ActiveRecord::Base` object.
|
270
268
|
- Any Ruby object that passes the
|
271
|
-
[Lint](
|
272
|
-
[code](
|
269
|
+
[Lint](https://www.rubydoc.info/gems/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
|
270
|
+
[(code)](lib/active_model/serializer/lint.rb).
|
273
271
|
|
274
272
|
ActiveModelSerializers provides a
|
275
|
-
[`ActiveModelSerializers::Model`](
|
273
|
+
[`ActiveModelSerializers::Model`](lib/active_model_serializers/model.rb),
|
276
274
|
which is a simple serializable PORO (Plain-Old Ruby Object).
|
277
275
|
|
278
276
|
`ActiveModelSerializers::Model` may be used either as a reference implementation, or in production code.
|
@@ -300,7 +298,7 @@ ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'),
|
|
300
298
|
|
301
299
|
## Semantic Versioning
|
302
300
|
|
303
|
-
This project adheres to [semver](
|
301
|
+
This project adheres to [semver](https://semver.org/)
|
304
302
|
|
305
303
|
## Contributing
|
306
304
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/class/attribute'
|
2
4
|
require 'active_model_serializers/serialization_context'
|
3
5
|
|
@@ -21,7 +23,15 @@ module ActionController
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def namespace_for_serializer
|
24
|
-
@namespace_for_serializer ||= self.class
|
26
|
+
@namespace_for_serializer ||= namespace_for_class(self.class) unless namespace_for_class(self.class) == Object
|
27
|
+
end
|
28
|
+
|
29
|
+
def namespace_for_class(klass)
|
30
|
+
if Module.method_defined?(:module_parent)
|
31
|
+
klass.module_parent
|
32
|
+
else
|
33
|
+
klass.parent
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
def serialization_scope
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'jsonapi/include_directive'
|
3
4
|
require 'active_model/serializer/collection_serializer'
|
4
5
|
require 'active_model/serializer/array_serializer'
|
@@ -18,16 +19,17 @@ module ActiveModel
|
|
18
19
|
# @see #serializable_hash for more details on these valid keys.
|
19
20
|
SERIALIZABLE_HASH_VALID_KEYS = [:only, :except, :methods, :include, :root].freeze
|
20
21
|
extend ActiveSupport::Autoload
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
eager_autoload do
|
23
|
+
autoload :Adapter
|
24
|
+
autoload :Null
|
25
|
+
autoload :Attribute
|
26
|
+
autoload :Link
|
27
|
+
autoload :Association
|
28
|
+
autoload :Reflection
|
29
|
+
autoload :BelongsToReflection
|
30
|
+
autoload :HasOneReflection
|
31
|
+
autoload :HasManyReflection
|
32
|
+
end
|
31
33
|
include ActiveSupport::Configurable
|
32
34
|
include Caching
|
33
35
|
|
@@ -70,7 +72,7 @@ module ActiveModel
|
|
70
72
|
# Used to cache serializer name => serializer class
|
71
73
|
# when looked up by Serializer.get_serializer_for.
|
72
74
|
def self.serializers_cache
|
73
|
-
@serializers_cache ||=
|
75
|
+
@serializers_cache ||= Concurrent::Map.new
|
74
76
|
end
|
75
77
|
|
76
78
|
# @api private
|
@@ -91,7 +93,7 @@ module ActiveModel
|
|
91
93
|
if serializer_class
|
92
94
|
serializer_class
|
93
95
|
elsif klass.superclass
|
94
|
-
get_serializer_for(klass.superclass)
|
96
|
+
get_serializer_for(klass.superclass, namespace)
|
95
97
|
else
|
96
98
|
nil # No serializer found
|
97
99
|
end
|
@@ -142,6 +144,7 @@ module ActiveModel
|
|
142
144
|
# Make JSON API top-level jsonapi member opt-in
|
143
145
|
# ref: http://jsonapi.org/format/#document-top-level
|
144
146
|
config.jsonapi_include_toplevel_object = false
|
147
|
+
config.jsonapi_use_foreign_key_on_belongs_to_relationship = false
|
145
148
|
config.include_data_default = true
|
146
149
|
|
147
150
|
# For configuring how serializers are found.
|
@@ -274,9 +277,14 @@ module ActiveModel
|
|
274
277
|
# link(:self) { "http://example.com/resource/#{object.id}" }
|
275
278
|
# @example
|
276
279
|
# link :resource, "http://example.com/resource"
|
280
|
+
# @example
|
281
|
+
# link(:callback, if: :internal?), { "http://example.com/callback" }
|
277
282
|
#
|
278
|
-
def self.link(name,
|
279
|
-
|
283
|
+
def self.link(name, *args, &block)
|
284
|
+
options = args.extract_options!
|
285
|
+
# For compatibility with the use case of passing link directly as string argument
|
286
|
+
# without block, we are creating a wrapping block
|
287
|
+
_links[name] = Link.new(name, options, block || ->(_serializer) { args.first })
|
280
288
|
end
|
281
289
|
|
282
290
|
# Set the JSON API meta attribute of a serializer.
|
@@ -337,10 +345,10 @@ module ActiveModel
|
|
337
345
|
# @return [Enumerator<Association>]
|
338
346
|
def associations(include_directive = ActiveModelSerializers.default_include_directive, include_slice = nil)
|
339
347
|
include_slice ||= include_directive
|
340
|
-
return Enumerator.new unless object
|
348
|
+
return Enumerator.new {} unless object
|
341
349
|
|
342
350
|
Enumerator.new do |y|
|
343
|
-
self.class._reflections.each do |key, reflection|
|
351
|
+
(self.instance_reflections ||= self.class._reflections.deep_dup).each do |key, reflection|
|
344
352
|
next if reflection.excluded?(self)
|
345
353
|
next unless include_directive.key?(key)
|
346
354
|
|
@@ -356,6 +364,9 @@ module ActiveModel
|
|
356
364
|
def serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance)
|
357
365
|
adapter_options ||= {}
|
358
366
|
options[:include_directive] ||= ActiveModel::Serializer.include_directive_from_options(adapter_options)
|
367
|
+
if (fieldset = adapter_options[:fieldset])
|
368
|
+
options[:fields] = fieldset.fields_for(json_key)
|
369
|
+
end
|
359
370
|
resource = attributes_hash(adapter_options, options, adapter_instance)
|
360
371
|
relationships = associations_hash(adapter_options, options, adapter_instance)
|
361
372
|
resource.merge(relationships)
|
@@ -370,7 +381,12 @@ module ActiveModel
|
|
370
381
|
|
371
382
|
# Used by adapter as resource root.
|
372
383
|
def json_key
|
373
|
-
root || _type ||
|
384
|
+
root || _type ||
|
385
|
+
begin
|
386
|
+
object.class.model_name.to_s.underscore
|
387
|
+
rescue ArgumentError
|
388
|
+
'anonymous_object'
|
389
|
+
end
|
374
390
|
end
|
375
391
|
|
376
392
|
def read_attribute_for_serialization(attr)
|
@@ -404,6 +420,6 @@ module ActiveModel
|
|
404
420
|
|
405
421
|
protected
|
406
422
|
|
407
|
-
attr_accessor :instance_options
|
423
|
+
attr_accessor :instance_options, :instance_reflections
|
408
424
|
end
|
409
425
|
end
|