active_model_serializers 0.10.6 → 0.10.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +114 -1
  3. data/README.md +21 -24
  4. data/lib/action_controller/serialization.rb +11 -1
  5. data/lib/active_model/serializable_resource.rb +2 -0
  6. data/lib/active_model/serializer/adapter/attributes.rb +2 -0
  7. data/lib/active_model/serializer/adapter/base.rb +2 -0
  8. data/lib/active_model/serializer/adapter/json.rb +2 -0
  9. data/lib/active_model/serializer/adapter/json_api.rb +2 -0
  10. data/lib/active_model/serializer/adapter/null.rb +2 -0
  11. data/lib/active_model/serializer/adapter.rb +2 -0
  12. data/lib/active_model/serializer/array_serializer.rb +2 -0
  13. data/lib/active_model/serializer/association.rb +2 -0
  14. data/lib/active_model/serializer/attribute.rb +2 -0
  15. data/lib/active_model/serializer/belongs_to_reflection.rb +2 -0
  16. data/lib/active_model/serializer/collection_serializer.rb +17 -5
  17. data/lib/active_model/serializer/concerns/caching.rb +7 -2
  18. data/lib/active_model/serializer/error_serializer.rb +2 -0
  19. data/lib/active_model/serializer/errors_serializer.rb +2 -0
  20. data/lib/active_model/serializer/field.rb +2 -0
  21. data/lib/active_model/serializer/fieldset.rb +3 -1
  22. data/lib/active_model/serializer/has_many_reflection.rb +2 -0
  23. data/lib/active_model/serializer/has_one_reflection.rb +2 -0
  24. data/lib/active_model/serializer/lazy_association.rb +6 -2
  25. data/lib/active_model/serializer/link.rb +23 -0
  26. data/lib/active_model/serializer/lint.rb +2 -0
  27. data/lib/active_model/serializer/null.rb +2 -0
  28. data/lib/active_model/serializer/reflection.rb +10 -5
  29. data/lib/active_model/serializer/version.rb +3 -1
  30. data/lib/active_model/serializer.rb +37 -19
  31. data/lib/active_model_serializers/adapter/attributes.rb +23 -0
  32. data/lib/active_model_serializers/adapter/base.rb +2 -0
  33. data/lib/active_model_serializers/adapter/json.rb +2 -0
  34. data/lib/active_model_serializers/adapter/json_api/deserialization.rb +3 -1
  35. data/lib/active_model_serializers/adapter/json_api/error.rb +2 -0
  36. data/lib/active_model_serializers/adapter/json_api/jsonapi.rb +2 -0
  37. data/lib/active_model_serializers/adapter/json_api/link.rb +2 -0
  38. data/lib/active_model_serializers/adapter/json_api/meta.rb +2 -0
  39. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +45 -20
  40. data/lib/active_model_serializers/adapter/json_api/relationship.rb +18 -4
  41. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +33 -25
  42. data/lib/active_model_serializers/adapter/json_api.rb +14 -9
  43. data/lib/active_model_serializers/adapter/null.rb +2 -0
  44. data/lib/active_model_serializers/adapter.rb +3 -1
  45. data/lib/active_model_serializers/callbacks.rb +2 -0
  46. data/lib/active_model_serializers/deprecate.rb +2 -0
  47. data/lib/active_model_serializers/deserialization.rb +2 -0
  48. data/lib/active_model_serializers/json_pointer.rb +2 -0
  49. data/lib/active_model_serializers/logging.rb +2 -0
  50. data/lib/active_model_serializers/lookup_chain.rb +2 -0
  51. data/lib/active_model_serializers/model/caching.rb +26 -0
  52. data/lib/active_model_serializers/model.rb +2 -0
  53. data/lib/active_model_serializers/railtie.rb +4 -0
  54. data/lib/active_model_serializers/register_jsonapi_renderer.rb +2 -0
  55. data/lib/active_model_serializers/serializable_resource.rb +4 -2
  56. data/lib/active_model_serializers/serialization_context.rb +2 -0
  57. data/lib/active_model_serializers/test/schema.rb +2 -0
  58. data/lib/active_model_serializers/test/serializer.rb +2 -0
  59. data/lib/active_model_serializers/test.rb +2 -0
  60. data/lib/active_model_serializers.rb +21 -11
  61. data/lib/generators/rails/resource_override.rb +2 -0
  62. data/lib/generators/rails/serializer_generator.rb +2 -0
  63. data/lib/grape/active_model_serializers.rb +2 -0
  64. data/lib/grape/formatters/active_model_serializers.rb +2 -0
  65. data/lib/grape/helpers/active_model_serializers.rb +2 -0
  66. data/lib/tasks/rubocop.rake +2 -0
  67. metadata +43 -298
  68. data/.github/ISSUE_TEMPLATE.md +0 -29
  69. data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
  70. data/.gitignore +0 -35
  71. data/.rubocop.yml +0 -105
  72. data/.simplecov +0 -110
  73. data/.travis.yml +0 -55
  74. data/CODE_OF_CONDUCT.md +0 -74
  75. data/CONTRIBUTING.md +0 -105
  76. data/Gemfile +0 -56
  77. data/Rakefile +0 -74
  78. data/active_model_serializers.gemspec +0 -63
  79. data/appveyor.yml +0 -30
  80. data/bin/bench +0 -171
  81. data/bin/bench_regression +0 -316
  82. data/bin/rubocop +0 -38
  83. data/bin/serve_benchmark +0 -39
  84. data/docs/README.md +0 -41
  85. data/docs/STYLE.md +0 -58
  86. data/docs/general/adapters.md +0 -263
  87. data/docs/general/caching.md +0 -58
  88. data/docs/general/configuration_options.md +0 -169
  89. data/docs/general/deserialization.md +0 -100
  90. data/docs/general/fields.md +0 -31
  91. data/docs/general/getting_started.md +0 -133
  92. data/docs/general/instrumentation.md +0 -40
  93. data/docs/general/key_transforms.md +0 -40
  94. data/docs/general/logging.md +0 -21
  95. data/docs/general/rendering.md +0 -293
  96. data/docs/general/serializers.md +0 -480
  97. data/docs/how-open-source-maintained.jpg +0 -0
  98. data/docs/howto/add_pagination_links.md +0 -138
  99. data/docs/howto/add_relationship_links.md +0 -140
  100. data/docs/howto/add_root_key.md +0 -55
  101. data/docs/howto/grape_integration.md +0 -42
  102. data/docs/howto/outside_controller_use.md +0 -66
  103. data/docs/howto/passing_arbitrary_options.md +0 -27
  104. data/docs/howto/serialize_poro.md +0 -73
  105. data/docs/howto/test.md +0 -154
  106. data/docs/howto/upgrade_from_0_8_to_0_10.md +0 -265
  107. data/docs/integrations/ember-and-json-api.md +0 -147
  108. data/docs/integrations/grape.md +0 -19
  109. data/docs/jsonapi/errors.md +0 -56
  110. data/docs/jsonapi/schema/schema.json +0 -366
  111. data/docs/jsonapi/schema.md +0 -151
  112. data/docs/rfcs/0000-namespace.md +0 -106
  113. data/docs/rfcs/template.md +0 -15
  114. data/test/action_controller/adapter_selector_test.rb +0 -62
  115. data/test/action_controller/explicit_serializer_test.rb +0 -135
  116. data/test/action_controller/json/include_test.rb +0 -246
  117. data/test/action_controller/json_api/deserialization_test.rb +0 -112
  118. data/test/action_controller/json_api/errors_test.rb +0 -40
  119. data/test/action_controller/json_api/fields_test.rb +0 -66
  120. data/test/action_controller/json_api/linked_test.rb +0 -202
  121. data/test/action_controller/json_api/pagination_test.rb +0 -116
  122. data/test/action_controller/json_api/transform_test.rb +0 -189
  123. data/test/action_controller/lookup_proc_test.rb +0 -49
  124. data/test/action_controller/namespace_lookup_test.rb +0 -232
  125. data/test/action_controller/serialization_scope_name_test.rb +0 -235
  126. data/test/action_controller/serialization_test.rb +0 -472
  127. data/test/active_model_serializers/adapter_for_test.rb +0 -208
  128. data/test/active_model_serializers/json_pointer_test.rb +0 -22
  129. data/test/active_model_serializers/logging_test.rb +0 -77
  130. data/test/active_model_serializers/model_test.rb +0 -142
  131. data/test/active_model_serializers/railtie_test_isolated.rb +0 -68
  132. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +0 -161
  133. data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -71
  134. data/test/active_model_serializers/test/schema_test.rb +0 -131
  135. data/test/active_model_serializers/test/serializer_test.rb +0 -62
  136. data/test/active_record_test.rb +0 -9
  137. data/test/adapter/attributes_test.rb +0 -40
  138. data/test/adapter/deprecation_test.rb +0 -100
  139. data/test/adapter/json/belongs_to_test.rb +0 -45
  140. data/test/adapter/json/collection_test.rb +0 -104
  141. data/test/adapter/json/has_many_test.rb +0 -53
  142. data/test/adapter/json/transform_test.rb +0 -93
  143. data/test/adapter/json_api/belongs_to_test.rb +0 -155
  144. data/test/adapter/json_api/collection_test.rb +0 -96
  145. data/test/adapter/json_api/errors_test.rb +0 -76
  146. data/test/adapter/json_api/fields_test.rb +0 -96
  147. data/test/adapter/json_api/has_many_embed_ids_test.rb +0 -43
  148. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -96
  149. data/test/adapter/json_api/has_many_test.rb +0 -173
  150. data/test/adapter/json_api/has_one_test.rb +0 -80
  151. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +0 -183
  152. data/test/adapter/json_api/json_api_test.rb +0 -33
  153. data/test/adapter/json_api/linked_test.rb +0 -413
  154. data/test/adapter/json_api/links_test.rb +0 -95
  155. data/test/adapter/json_api/pagination_links_test.rb +0 -193
  156. data/test/adapter/json_api/parse_test.rb +0 -137
  157. data/test/adapter/json_api/relationship_test.rb +0 -397
  158. data/test/adapter/json_api/resource_identifier_test.rb +0 -110
  159. data/test/adapter/json_api/resource_meta_test.rb +0 -100
  160. data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -82
  161. data/test/adapter/json_api/transform_test.rb +0 -512
  162. data/test/adapter/json_api/type_test.rb +0 -61
  163. data/test/adapter/json_test.rb +0 -46
  164. data/test/adapter/null_test.rb +0 -22
  165. data/test/adapter/polymorphic_test.rb +0 -171
  166. data/test/adapter_test.rb +0 -67
  167. data/test/array_serializer_test.rb +0 -22
  168. data/test/benchmark/app.rb +0 -65
  169. data/test/benchmark/benchmarking_support.rb +0 -67
  170. data/test/benchmark/bm_active_record.rb +0 -81
  171. data/test/benchmark/bm_adapter.rb +0 -38
  172. data/test/benchmark/bm_caching.rb +0 -119
  173. data/test/benchmark/bm_lookup_chain.rb +0 -83
  174. data/test/benchmark/bm_transform.rb +0 -45
  175. data/test/benchmark/config.ru +0 -3
  176. data/test/benchmark/controllers.rb +0 -83
  177. data/test/benchmark/fixtures.rb +0 -219
  178. data/test/cache_test.rb +0 -651
  179. data/test/collection_serializer_test.rb +0 -123
  180. data/test/fixtures/active_record.rb +0 -113
  181. data/test/fixtures/poro.rb +0 -225
  182. data/test/generators/scaffold_controller_generator_test.rb +0 -24
  183. data/test/generators/serializer_generator_test.rb +0 -75
  184. data/test/grape_test.rb +0 -196
  185. data/test/lint_test.rb +0 -49
  186. data/test/logger_test.rb +0 -20
  187. data/test/poro_test.rb +0 -9
  188. data/test/serializable_resource_test.rb +0 -79
  189. data/test/serializers/association_macros_test.rb +0 -37
  190. data/test/serializers/associations_test.rb +0 -424
  191. data/test/serializers/attribute_test.rb +0 -153
  192. data/test/serializers/attributes_test.rb +0 -52
  193. data/test/serializers/caching_configuration_test_isolated.rb +0 -170
  194. data/test/serializers/configuration_test.rb +0 -32
  195. data/test/serializers/fieldset_test.rb +0 -14
  196. data/test/serializers/meta_test.rb +0 -202
  197. data/test/serializers/options_test.rb +0 -32
  198. data/test/serializers/read_attribute_for_serialization_test.rb +0 -79
  199. data/test/serializers/reflection_test.rb +0 -427
  200. data/test/serializers/root_test.rb +0 -21
  201. data/test/serializers/serialization_test.rb +0 -55
  202. data/test/serializers/serializer_for_test.rb +0 -136
  203. data/test/serializers/serializer_for_with_namespace_test.rb +0 -88
  204. data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  205. data/test/support/isolated_unit.rb +0 -82
  206. data/test/support/rails5_shims.rb +0 -53
  207. data/test/support/rails_app.rb +0 -38
  208. data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  209. data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
  210. data/test/support/schemas/custom/show.json +0 -7
  211. data/test/support/schemas/hyper_schema.json +0 -93
  212. data/test/support/schemas/render_using_json_api.json +0 -43
  213. data/test/support/schemas/simple_json_pointers.json +0 -10
  214. data/test/support/serialization_testing.rb +0 -71
  215. data/test/test_helper.rb +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fbc0f811b036c328dccf411b6f8080b6605d8740
4
- data.tar.gz: d4a0f6f7799b074aff45bc103c9c19b9ea873ab1
2
+ SHA256:
3
+ metadata.gz: 94ecdeeabcad7f33e6b2891f2354edeb1fdabf444d9938014d839b554f0a5ab7
4
+ data.tar.gz: cd43b9ceddf4920feb4efae6c5d0748bbb6e37111328c015cdcca06ba8f9d86d
5
5
  SHA512:
6
- metadata.gz: 121ed054788e585e48e76af3e98490930fd26f18ebdd28d80d07cba78fe9b7c3aed8ea1e1f15ace59debb73562383657f89e4d52fa2c54391424ea53c3701a38
7
- data.tar.gz: 88ab9022b49348ec463547196300480bcf02139d67cc11adfcbf8c5e4e38c3e44b27cdde7687baab54f8f8ce4bbe4fa606079dffae51ad7be42427dc15955d6e
6
+ metadata.gz: 93b28755ff8f015277534dfc971cab0ef5bf30745bebb34c90e2f6e17c1cb611ef1100ba9e484ebdd1dc415d2c9d1c7e715984a1052e75daada8f712b1126850
7
+ data.tar.gz: 86d257304d0e58b87e82a8c32f55a7722ffdc568dd394ac93214dfe382bf8ff27c8bed24c11f6a948184a16a67ad5fa7bbaf98f2443b2d11c017ce5463c58947
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.6...master)
3
+ ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.13...0-10-stable)
4
4
 
5
5
  Breaking changes:
6
6
 
@@ -10,6 +10,119 @@ Fixes:
10
10
 
11
11
  Misc:
12
12
 
13
+ ### [v0.10.13 (2022-01013)](https://github.com/rails-api/active_model_serializers/compare/v0.10.12...v0.10.13)
14
+
15
+ Fixes:
16
+
17
+ - [#2399](https://github.com/rails-api/active_model_serializers/pull/2399) Handles edge case where requested current_page > total_pages (@f3z0)
18
+
19
+ ### [v0.10.12 (2020-12-10)](https://github.com/rails-api/active_model_serializers/compare/v0.10.11...v0.10.12)
20
+
21
+ Fixes:
22
+
23
+ - [#2398](https://github.com/rails-api/active_model_serializers/pull/2398) Update rails dependency to < 6.2 (@ritikesh)
24
+
25
+ ### [v0.10.11 (2020-12-04)](https://github.com/rails-api/active_model_serializers/compare/v0.10.10...v0.10.11)
26
+
27
+ Features:
28
+
29
+ - [#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)
30
+
31
+ Fixes:
32
+
33
+ - [#2344](https://github.com/rails-api/active_model_serializers/pull/2344) Fixes #2341 introduced since #2223 (@wasifhossain)
34
+ - [#2395](https://github.com/rails-api/active_model_serializers/pull/2395) remove explicit require for thread_safe (@ritikesh)
35
+
36
+ ### [v0.10.10 (2019-07-13)](https://github.com/rails-api/active_model_serializers/compare/v0.10.9...v0.10.10)
37
+
38
+ Fixes:
39
+
40
+ - [#2319](https://github.com/rails-api/active_model_serializers/pull/2319) Fixes #2316. (@kylekeesling)
41
+ - Fix Rails 6.0 deprication warnings
42
+ - update test fixture schema to use `timestamps` instead of `timestamp`
43
+ - [#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)
44
+ - [#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)
45
+ - Fixes incorrect json-api generation when `jsonapi_use_foreign_key_on_belongs_to_relationship` is `true` and the relationship is blank
46
+ - [#2172](https://github.com/rails-api/active_model_serializers/pull/2172) Preserve the namespace when falling back to a superclass serializer
47
+
48
+ Misc:
49
+
50
+ - [#2327](https://github.com/rails-api/active_model_serializers/pull/2327) Add support for Ruby 2.6 on Travis CI (@wasifhossain)
51
+ - [#2304](https://github.com/rails-api/active_model_serializers/pull/2304) Slim down bundled gem by excluding test files and docs (@greysteil)
52
+
53
+ ### [v0.10.9 (2019-02-08)](https://github.com/rails-api/active_model_serializers/compare/v0.10.8...v0.10.9)
54
+
55
+ Fixes:
56
+
57
+ - [#2288](https://github.com/rails-api/active_model_serializers/pull/2288)
58
+ Change the fetch method to deal with recyclable key cache strategy.
59
+ Fixes #2287. (@cintamani, @wasifhossain)
60
+ - [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated.
61
+
62
+ Misc:
63
+
64
+ - [#2309](https://github.com/rails-api/active_model_serializers/pull/2309) Performance and memory usage fixes
65
+
66
+ ### [v0.10.8 (2018-11-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.7...v0.10.8)
67
+
68
+ Features:
69
+ - [#2279](https://github.com/rails-api/active_model_serializers/pull/2279) Support condition options in serializer link statements
70
+
71
+ Fixes:
72
+
73
+ - [#2296](https://github.com/rails-api/active_model_serializers/pull/2296) Fixes #2295 (@Hirurg103)
74
+ - Fix finding of namespaced serializer and non-namespaced model.
75
+ - [#2289](https://github.com/rails-api/active_model_serializers/pull/2289) Fixes #2255 (@f-mer)
76
+ - Fix autoloading race condition, especially in Rails 5.
77
+ - [#2299](https://github.com/rails-api/active_model_serializers/pull/2299) Fixes #2270 (@chau-bao-long via #2276)
78
+ - Fix reflection thread-safety bug
79
+
80
+ ### [v0.10.7 (2017-11-14)](https://github.com/rails-api/active_model_serializers/compare/v0.10.6...v0.10.7)
81
+
82
+ Regressions Fixed From v0.10.6:
83
+
84
+ - [#2211](https://github.com/rails-api/active_model_serializers/pull/2211). Fixes #2125, #2160. (@bf4)
85
+ - Fix polymorphic belongs_to tests; passes on v0.10.5, fails on v0.10.6
86
+ - Fix JSON:API polymorphic type regression from v0.10.5
87
+ - Fix JSON:API: for_type_and_id should always inflect_type
88
+ ```
89
+ Should Serializer._type ever be inflected?
90
+ Right now, it won't be, but association.serializer._type will be inflected.
91
+
92
+ That's the current behavior.
93
+ ```
94
+ - [#2216](https://github.com/rails-api/active_model_serializers/pull/2216). Fixes #2132, #2180. (@bf4)
95
+ - Fix JSON:API: Serialize resource type for unpersisted records (blank id)
96
+ - [#2218](https://github.com/rails-api/active_model_serializers/pull/2218). Fixes #2178. (@bf4)
97
+ - Fix JSON:API: Make using foreign key on belongs_to opt-in. No effect on polymorphic relationships.
98
+ ```
99
+ # set to true to opt-in
100
+ ActiveModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
101
+ ```
102
+
103
+ Features:
104
+
105
+ - [#2136](https://github.com/rails-api/active_model_serializers/pull/2136) Enable inclusion of sideloaded relationship objects by `key`. (@caomania)
106
+ - [#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)
107
+ - [#2130](https://github.com/rails-api/active_model_serializers/pull/2130) Allow serialized ID to be overwritten for belongs-to relationships. (@greysteil)
108
+ - [#2189](https://github.com/rails-api/active_model_serializers/pull/2189)
109
+ Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.3']`
110
+ (@tagliala)
111
+
112
+ Fixes:
113
+
114
+ - [#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)
115
+ - [#2200](https://github.com/rails-api/active_model_serializers/pull/2200) Fix deserialization of polymorphic relationships. (@dennis95stumm)
116
+ - [#2214](https://github.com/rails-api/active_model_serializers/pull/2214) Fail if unable to infer collection type with json adapter. (@jmeredith16)
117
+ - [#2149](https://github.com/rails-api/active_model_serializers/pull/2149) Always include self, first, last pagination link. (@mecampbellsoup)
118
+ - [#2179](https://github.com/rails-api/active_model_serializers/pull/2179) Fixes #2173, Pass block to Enumerator.new. (@drn)
119
+
120
+ Misc:
121
+
122
+ - [#2176](https://github.com/rails-api/active_model_serializers/pull/2176) Documentation for global adapter config. (@mrpinsky)
123
+ - [#2215](https://github.com/rails-api/active_model_serializers/pull/2215) Update `serializers.md` documentation to denote alternate use cases for `scope`. (@stratigos)
124
+ - [#2212](https://github.com/rails-api/active_model_serializers/pull/2212) Remove legacy has_many_embed_ids test. (@bf4)
125
+
13
126
  ### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6)
14
127
 
15
128
  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=master" alt="Build Status" ></a>
8
- <a href="https://ci.appveyor.com/project/joaomdmoura/active-model-serializers/branch/master"><img src="https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true" alt="Build status"></a>
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>
@@ -13,7 +13,6 @@
13
13
  <td>
14
14
  <a href="https://codeclimate.com/github/rails-api/active_model_serializers"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg" alt="Code Quality"></a>
15
15
  <a href="https://codebeat.co/projects/github-com-rails-api-active_model_serializers"><img src="https://codebeat.co/badges/a9ab35fa-8b5a-4680-9d4e-a81f9a55ebcd" alt="codebeat" ></a>
16
- <a href="https://codeclimate.com/github/rails-api/active_model_serializers/coverage"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg" alt="Test Coverage"></a>
17
16
  </td>
18
17
  </tr>
19
18
  <tr>
@@ -41,7 +40,7 @@ these methods to the adapter.)
41
40
 
42
41
  By default ActiveModelSerializers will use the **Attributes Adapter** (no JSON root).
43
42
  But we strongly advise you to use **JsonApi Adapter**, which
44
- follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
43
+ follows 1.0 of the format specified in [jsonapi.org/format](https://jsonapi.org/format).
45
44
  Check how to change the adapter in the sections below.
46
45
 
47
46
  `0.10.x` is **not** backward compatible with `0.9.x` nor `0.8.x`.
@@ -49,8 +48,6 @@ Check how to change the adapter in the sections below.
49
48
  `0.10.x` is based on the `0.8.0` code, but with a more flexible
50
49
  architecture. We'd love your help. [Learn how you can help here.](CONTRIBUTING.md)
51
50
 
52
- It is generally safe and recommended to use the master branch.
53
-
54
51
  ## Installation
55
52
 
56
53
  Add this line to your application's Gemfile:
@@ -77,9 +74,9 @@ More information is available in the [Guides](docs) and
77
74
  If you find a bug, please report an [Issue](https://github.com/rails-api/active_model_serializers/issues/new)
78
75
  and see our [contributing guide](CONTRIBUTING.md).
79
76
 
80
- If you have a question, please [post to Stack Overflow](http://stackoverflow.com/questions/tagged/active-model-serializers).
77
+ If you have a question, please [post to Stack Overflow](https://stackoverflow.com/questions/tagged/active-model-serializers).
81
78
 
82
- If you'd like to chat, we have a [community slack](http://amserializers.herokuapp.com).
79
+ If you'd like to chat, we have a [community slack](https://amserializers.herokuapp.com).
83
80
 
84
81
  Thanks!
85
82
 
@@ -89,14 +86,14 @@ If you're reading this at https://github.com/rails-api/active_model_serializers
89
86
  reading documentation for our `master`, which may include features that have not
90
87
  been released yet. Please see below for the documentation relevant to you.
91
88
 
92
- - [0.10 (master) Documentation](https://github.com/rails-api/active_model_serializers/tree/master)
93
- - [0.10.6 (latest release) Documentation](https://github.com/rails-api/active_model_serializers/tree/v0.10.6)
94
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/active_model_serializers/0.10.6)
95
- - [Guides](docs)
89
+ - [0.10 (0-10-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-10-stable)
90
+ - [0.10.10 (latest release) Documentation](https://github.com/rails-api/active_model_serializers/tree/v0.10.10)
91
+ - [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.10.10)
92
+ - [Guides](docs)
96
93
  - [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
97
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-9-stable)
94
+ - [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.9.7)
98
95
  - [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
99
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-8-stable)
96
+ - [![API Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/active_model_serializers/0.8.4)
100
97
 
101
98
 
102
99
  ## High-level behavior
@@ -173,12 +170,12 @@ The original design is also available [here](https://github.com/rails-api/active
173
170
 
174
171
  ### ActiveModel::Serializer
175
172
 
176
- An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serialization.rb)
173
+ An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb)
177
174
  and exposes an `attributes` method, among a few others.
178
175
  It allows you to specify which attributes and associations should be represented in the serializatation of the resource.
179
176
  It requires an adapter to transform its attributes into a JSON document; it cannot be serialized itself.
180
177
  It may be useful to think of it as a
181
- [presenter](http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
178
+ [presenter](https://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
182
179
 
183
180
  #### ActiveModel::CollectionSerializer
184
181
 
@@ -187,10 +184,10 @@ and, if there is no serializer, primitives.
187
184
 
188
185
  ### ActiveModelSerializers::Adapter::Base
189
186
 
190
- The **`ActiveModelSerializeres::Adapter::Base`** describes the structure of the JSON document generated from a
187
+ The **`ActiveModelSerializers::Adapter::Base`** describes the structure of the JSON document generated from a
191
188
  serializer. For example, the `Attributes` example represents each serializer as its
192
189
  unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
193
- API](http://jsonapi.org/) document.
190
+ API](https://jsonapi.org/) document.
194
191
 
195
192
  ### ActiveModelSerializers::SerializableResource
196
193
 
@@ -231,7 +228,7 @@ High-level overview:
231
228
  - `:each_serializer` specifies the serializer for each resource in the collection.
232
229
  - For a **single resource**, the `:serializer` option is the resource serializer.
233
230
  - Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
234
- [`ADAPTER_OPTION_KEYS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/serializable_resource.rb#L5).
231
+ [`ADAPTER_OPTION_KEYS`](lib/active_model_serializers/serializable_resource.rb#L5).
235
232
  The remaining options are serializer options.
236
233
 
237
234
  Details:
@@ -256,7 +253,7 @@ Details:
256
253
  2. `adapter_instance = ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)`
257
254
  1. **ActiveModel::Serializer::CollectionSerializer#new**
258
255
  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/a54d237e2828fe6bab1ea5dfe6360d4ecc8214cd/lib/active_model/serializer/array_serializer.rb#L14-L16).
256
+ 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
257
  1. **ActiveModel::Serializer#attributes** is used by the adapter to get the attributes for
261
258
  resource as defined by the serializer.
262
259
 
@@ -268,11 +265,11 @@ to know about, but not part of ActiveModelSerializers.)
268
265
 
269
266
  - An `ActiveRecord::Base` object.
270
267
  - Any Ruby object that passes the
271
- [Lint](http://www.rubydoc.info/github/rails-api/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
272
- [code](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/lint.rb).
268
+ [Lint](https://www.rubydoc.info/gems/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
269
+ [(code)](lib/active_model/serializer/lint.rb).
273
270
 
274
271
  ActiveModelSerializers provides a
275
- [`ActiveModelSerializers::Model`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/model.rb),
272
+ [`ActiveModelSerializers::Model`](lib/active_model_serializers/model.rb),
276
273
  which is a simple serializable PORO (Plain-Old Ruby Object).
277
274
 
278
275
  `ActiveModelSerializers::Model` may be used either as a reference implementation, or in production code.
@@ -300,7 +297,7 @@ ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'),
300
297
 
301
298
  ## Semantic Versioning
302
299
 
303
- This project adheres to [semver](http://semver.org/)
300
+ This project adheres to [semver](https://semver.org/)
304
301
 
305
302
  ## Contributing
306
303
 
@@ -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.parent unless self.class.parent == Object
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model_serializers/adapter'
2
4
  require 'active_model_serializers/deprecate'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model/serializer/collection_serializer'
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model/serializer/lazy_association'
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model/serializer/field'
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  class CollectionSerializer
@@ -19,11 +21,10 @@ module ActiveModel
19
21
 
20
22
  # @api private
21
23
  def serializable_hash(adapter_options, options, adapter_instance)
22
- include_directive = ActiveModel::Serializer.include_directive_from_options(adapter_options)
23
- adapter_options[:cached_attributes] ||= ActiveModel::Serializer.cache_read_multi(self, adapter_instance, include_directive)
24
- adapter_opts = adapter_options.merge(include_directive: include_directive)
24
+ options[:include_directive] ||= ActiveModel::Serializer.include_directive_from_options(adapter_options)
25
+ options[:cached_attributes] ||= ActiveModel::Serializer.cache_read_multi(self, adapter_instance, options[:include_directive])
25
26
  serializers.map do |serializer|
26
- serializer.serializable_hash(adapter_opts, options, adapter_instance)
27
+ serializer.serializable_hash(adapter_options, options, adapter_instance)
27
28
  end
28
29
  end
29
30
 
@@ -46,7 +47,12 @@ module ActiveModel
46
47
  # 3. get from collection name, if a named collection
47
48
  key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
48
49
  # 4. key may be nil for empty collection and no serializer option
49
- key && key.pluralize
50
+ key &&= key.pluralize
51
+ if raise_cannot_infer_root_key_error?
52
+ # 5. fail if the key cannot be determined
53
+ key || fail(CannotInferRootKeyError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
54
+ end
55
+ key
50
56
  end
51
57
  # rubocop:enable Metrics/CyclomaticComplexity
52
58
 
@@ -57,12 +63,18 @@ module ActiveModel
57
63
  object.respond_to?(:size)
58
64
  end
59
65
 
66
+ class CannotInferRootKeyError < StandardError; end
67
+
60
68
  protected
61
69
 
62
70
  attr_reader :serializers, :options
63
71
 
64
72
  private
65
73
 
74
+ def raise_cannot_infer_root_key_error?
75
+ ActiveModelSerializers.config.raise_cannot_infer_root_key_error
76
+ end
77
+
66
78
  def serializers_from_resources
67
79
  serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
68
80
  object.map do |resource|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  UndefinedCacheKey = Class.new(StandardError)
@@ -54,7 +56,8 @@ module ActiveModel
54
56
  def digest_caller_file(caller_line)
55
57
  serializer_file_path = caller_line[CALLER_FILE]
56
58
  serializer_file_contents = IO.read(serializer_file_path)
57
- Digest::MD5.hexdigest(serializer_file_contents)
59
+ algorithm = ActiveModelSerializers.config.use_sha1_digests ? Digest::SHA1 : Digest::MD5
60
+ algorithm.hexdigest(serializer_file_contents)
58
61
  rescue TypeError, Errno::ENOENT
59
62
  warn <<-EOF.strip_heredoc
60
63
  Cannot digest non-existent file: '#{caller_line}'.
@@ -281,7 +284,9 @@ module ActiveModel
281
284
  # Use object's cache_key if available, else derive a key from the object
282
285
  # Pass the `key` option to the `cache` declaration or override this method to customize the cache key
283
286
  def object_cache_key
284
- if object.respond_to?(:cache_key)
287
+ if object.respond_to?(:cache_key_with_version)
288
+ object.cache_key_with_version
289
+ elsif object.respond_to?(:cache_key)
285
290
  object.cache_key
286
291
  elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
287
292
  object_time_safe = object.updated_at
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  class ErrorSerializer < ActiveModel::Serializer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model/serializer/error_serializer'
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  # Holds all the meta-data about a field (i.e. attribute or association) as it was
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  class Fieldset
@@ -10,7 +12,7 @@ module ActiveModel
10
12
  end
11
13
 
12
14
  def fields_for(type)
13
- fields[type.singularize.to_sym] || fields[type.pluralize.to_sym]
15
+ fields[type.to_s.singularize.to_sym] || fields[type.to_s.pluralize.to_sym]
14
16
  end
15
17
 
16
18
  protected
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  # @api private
@@ -7,11 +9,12 @@ module ActiveModel
7
9
  delegate :collection?, to: :reflection
8
10
 
9
11
  def reflection_options
10
- @reflection_options ||= reflection.options.dup.reject { |k, _| !REFLECTION_OPTIONS.include?(k) }
12
+ @reflection_options ||= reflection.options.select { |k, _| REFLECTION_OPTIONS.include?(k) }
11
13
  end
12
14
 
13
15
  def object
14
- @object ||= reflection.value(
16
+ return @object if defined?(@object)
17
+ @object = reflection.value(
15
18
  association_options.fetch(:parent_serializer),
16
19
  association_options.fetch(:include_slice)
17
20
  )
@@ -76,6 +79,7 @@ module ActiveModel
76
79
  serializer_options[:serializer_context_class] = association_options.fetch(:parent_serializer).class
77
80
  serializer = reflection_options.fetch(:serializer, nil)
78
81
  serializer_options[:serializer] = serializer if serializer
82
+ serializer_options[:namespace] = reflection_options[:namespace] if reflection_options[:namespace]
79
83
  serializer_class.new(object, serializer_options)
80
84
  end
81
85
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model/serializer/field'
4
+
5
+ module ActiveModel
6
+ class Serializer
7
+ # Holds all the data about a serializer link
8
+ #
9
+ # @example
10
+ # class PostSerializer < ActiveModel::Serializer
11
+ # link :callback, if: :internal? do
12
+ # object.callback_link
13
+ # end
14
+ #
15
+ # def internal?
16
+ # instance_options[:internal] == true
17
+ # end
18
+ # end
19
+ #
20
+ class Link < Field
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  module Lint
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
5
  class Null < Serializer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model/serializer/field'
2
4
  require 'active_model/serializer/association'
3
5
 
@@ -85,8 +87,8 @@ module ActiveModel
85
87
  # meta ids: ids
86
88
  # end
87
89
  # end
88
- def link(name, value = nil)
89
- options[:links][name] = block_given? ? Proc.new : value
90
+ def link(name, value = nil, &block)
91
+ options[:links][name] = block_given? ? block : value
90
92
  :nil
91
93
  end
92
94
 
@@ -100,8 +102,8 @@ module ActiveModel
100
102
  # href object.blog.id.to_s
101
103
  # meta(id: object.blog.id)
102
104
  # end
103
- def meta(value = nil)
104
- options[:meta] = block_given? ? Proc.new : value
105
+ def meta(value = nil, &block)
106
+ options[:meta] = block_given? ? block : value
105
107
  :nil
106
108
  end
107
109
 
@@ -140,7 +142,7 @@ module ActiveModel
140
142
  def include_data?(include_slice)
141
143
  include_data_setting = options[:include_data_setting]
142
144
  case include_data_setting
143
- when :if_sideloaded then include_slice.key?(name)
145
+ when :if_sideloaded then include_slice.key?(options.fetch(:key, name))
144
146
  when true then true
145
147
  when false then false
146
148
  else fail ArgumentError, "Unknown include_data_setting '#{include_data_setting.inspect}'"
@@ -151,6 +153,9 @@ module ActiveModel
151
153
  # @yield [ActiveModel::Serializer]
152
154
  # @return [:nil, associated resource or resource collection]
153
155
  def value(serializer, include_slice)
156
+ # NOTE(BF): This method isn't thread-safe because the _reflections class attribute is not thread-safe
157
+ # Therefore, when we build associations from reflections, we dup the entire reflection instance.
158
+ # Better solutions much appreciated!
154
159
  @object = serializer.object
155
160
  @scope = serializer.scope
156
161
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Serializer
3
- VERSION = '0.10.6'.freeze
5
+ VERSION = '0.10.13'.freeze
4
6
  end
5
7
  end