active_model_serializers 0.10.0 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +17 -5
  4. data/CHANGELOG.md +112 -2
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +5 -2
  7. data/README.md +166 -26
  8. data/Rakefile +3 -3
  9. data/active_model_serializers.gemspec +21 -24
  10. data/appveyor.yml +9 -3
  11. data/docs/README.md +2 -1
  12. data/docs/general/adapters.md +4 -2
  13. data/docs/general/caching.md +7 -1
  14. data/docs/general/configuration_options.md +70 -1
  15. data/docs/general/deserialization.md +1 -1
  16. data/docs/general/fields.md +31 -0
  17. data/docs/general/logging.md +7 -0
  18. data/docs/general/rendering.md +44 -20
  19. data/docs/general/serializers.md +100 -11
  20. data/docs/howto/add_pagination_links.md +15 -16
  21. data/docs/howto/add_relationship_links.md +140 -0
  22. data/docs/howto/add_root_key.md +4 -0
  23. data/docs/howto/grape_integration.md +42 -0
  24. data/docs/howto/outside_controller_use.md +12 -4
  25. data/docs/howto/passing_arbitrary_options.md +2 -2
  26. data/docs/howto/serialize_poro.md +46 -5
  27. data/docs/howto/test.md +2 -0
  28. data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
  29. data/docs/integrations/ember-and-json-api.md +64 -32
  30. data/docs/jsonapi/schema.md +1 -1
  31. data/lib/action_controller/serialization.rb +13 -3
  32. data/lib/active_model/serializer/adapter/base.rb +2 -0
  33. data/lib/active_model/serializer/array_serializer.rb +8 -5
  34. data/lib/active_model/serializer/association.rb +19 -4
  35. data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
  36. data/lib/active_model/serializer/collection_serializer.rb +35 -12
  37. data/lib/active_model/serializer/{associations.rb → concerns/associations.rb} +13 -11
  38. data/lib/active_model/serializer/{attributes.rb → concerns/attributes.rb} +1 -1
  39. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +72 -113
  40. data/lib/active_model/serializer/{configuration.rb → concerns/configuration.rb} +25 -1
  41. data/lib/active_model/serializer/{links.rb → concerns/links.rb} +0 -0
  42. data/lib/active_model/serializer/{meta.rb → concerns/meta.rb} +0 -0
  43. data/lib/active_model/serializer/{type.rb → concerns/type.rb} +0 -0
  44. data/lib/active_model/serializer/error_serializer.rb +11 -7
  45. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  46. data/lib/active_model/serializer/has_many_reflection.rb +0 -3
  47. data/lib/active_model/serializer/has_one_reflection.rb +0 -3
  48. data/lib/active_model/serializer/lint.rb +134 -130
  49. data/lib/active_model/serializer/reflection.rb +37 -21
  50. data/lib/active_model/serializer/version.rb +1 -1
  51. data/lib/active_model/serializer.rb +76 -37
  52. data/lib/active_model_serializers/adapter/attributes.rb +3 -66
  53. data/lib/active_model_serializers/adapter/base.rb +39 -39
  54. data/lib/active_model_serializers/adapter/json_api/deserialization.rb +1 -1
  55. data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
  56. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
  57. data/lib/active_model_serializers/adapter/json_api/relationship.rb +30 -19
  58. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +23 -9
  59. data/lib/active_model_serializers/adapter/json_api.rb +44 -43
  60. data/lib/active_model_serializers/adapter.rb +6 -0
  61. data/lib/active_model_serializers/deprecate.rb +1 -2
  62. data/lib/active_model_serializers/deserialization.rb +2 -0
  63. data/lib/active_model_serializers/lookup_chain.rb +80 -0
  64. data/lib/active_model_serializers/model.rb +108 -28
  65. data/lib/active_model_serializers/railtie.rb +3 -1
  66. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  67. data/lib/active_model_serializers/serializable_resource.rb +6 -5
  68. data/lib/active_model_serializers/serialization_context.rb +10 -3
  69. data/lib/active_model_serializers/test/schema.rb +2 -2
  70. data/lib/active_model_serializers.rb +15 -0
  71. data/lib/generators/rails/resource_override.rb +1 -1
  72. data/lib/generators/rails/serializer_generator.rb +4 -4
  73. data/lib/grape/active_model_serializers.rb +7 -5
  74. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  75. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  76. data/test/action_controller/adapter_selector_test.rb +14 -5
  77. data/test/action_controller/explicit_serializer_test.rb +5 -4
  78. data/test/action_controller/json/include_test.rb +106 -27
  79. data/test/action_controller/json_api/errors_test.rb +8 -9
  80. data/test/action_controller/json_api/fields_test.rb +66 -0
  81. data/test/action_controller/json_api/linked_test.rb +29 -24
  82. data/test/action_controller/json_api/pagination_test.rb +19 -19
  83. data/test/action_controller/json_api/transform_test.rb +11 -3
  84. data/test/action_controller/lookup_proc_test.rb +49 -0
  85. data/test/action_controller/namespace_lookup_test.rb +232 -0
  86. data/test/action_controller/serialization_scope_name_test.rb +12 -6
  87. data/test/action_controller/serialization_test.rb +12 -9
  88. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  89. data/test/active_model_serializers/model_test.rb +137 -4
  90. data/test/active_model_serializers/railtie_test_isolated.rb +12 -7
  91. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +161 -0
  92. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  93. data/test/active_model_serializers/test/schema_test.rb +3 -2
  94. data/test/adapter/attributes_test.rb +40 -0
  95. data/test/adapter/json/collection_test.rb +14 -0
  96. data/test/adapter/json/has_many_test.rb +10 -2
  97. data/test/adapter/json/transform_test.rb +15 -15
  98. data/test/adapter/json_api/collection_test.rb +4 -3
  99. data/test/adapter/json_api/errors_test.rb +17 -19
  100. data/test/adapter/json_api/fields_test.rb +12 -3
  101. data/test/adapter/json_api/has_many_test.rb +49 -20
  102. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +183 -0
  103. data/test/adapter/json_api/json_api_test.rb +5 -7
  104. data/test/adapter/json_api/linked_test.rb +33 -12
  105. data/test/adapter/json_api/links_test.rb +4 -2
  106. data/test/adapter/json_api/pagination_links_test.rb +35 -8
  107. data/test/adapter/json_api/relationship_test.rb +309 -73
  108. data/test/adapter/json_api/resource_identifier_test.rb +27 -2
  109. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  110. data/test/adapter/json_api/transform_test.rb +263 -253
  111. data/test/adapter/json_api/type_test.rb +1 -1
  112. data/test/adapter/json_test.rb +8 -7
  113. data/test/adapter/null_test.rb +1 -2
  114. data/test/adapter/polymorphic_test.rb +5 -5
  115. data/test/adapter_test.rb +1 -1
  116. data/test/benchmark/app.rb +1 -1
  117. data/test/benchmark/benchmarking_support.rb +1 -1
  118. data/test/benchmark/bm_active_record.rb +81 -0
  119. data/test/benchmark/bm_adapter.rb +38 -0
  120. data/test/benchmark/bm_caching.rb +16 -16
  121. data/test/benchmark/bm_lookup_chain.rb +83 -0
  122. data/test/benchmark/bm_transform.rb +21 -10
  123. data/test/benchmark/controllers.rb +16 -17
  124. data/test/benchmark/fixtures.rb +72 -72
  125. data/test/cache_test.rb +235 -69
  126. data/test/collection_serializer_test.rb +25 -12
  127. data/test/fixtures/active_record.rb +45 -10
  128. data/test/fixtures/poro.rb +124 -181
  129. data/test/generators/serializer_generator_test.rb +23 -5
  130. data/test/grape_test.rb +170 -56
  131. data/test/lint_test.rb +1 -1
  132. data/test/logger_test.rb +13 -11
  133. data/test/serializable_resource_test.rb +18 -22
  134. data/test/serializers/association_macros_test.rb +3 -2
  135. data/test/serializers/associations_test.rb +132 -36
  136. data/test/serializers/attribute_test.rb +5 -3
  137. data/test/serializers/attributes_test.rb +1 -1
  138. data/test/serializers/caching_configuration_test_isolated.rb +6 -6
  139. data/test/serializers/fieldset_test.rb +1 -1
  140. data/test/serializers/meta_test.rb +12 -6
  141. data/test/serializers/options_test.rb +17 -6
  142. data/test/serializers/read_attribute_for_serialization_test.rb +3 -3
  143. data/test/serializers/root_test.rb +1 -1
  144. data/test/serializers/serialization_test.rb +2 -2
  145. data/test/serializers/serializer_for_test.rb +12 -10
  146. data/test/serializers/serializer_for_with_namespace_test.rb +88 -0
  147. data/test/support/isolated_unit.rb +5 -2
  148. data/test/support/rails5_shims.rb +8 -2
  149. data/test/support/rails_app.rb +2 -9
  150. data/test/support/serialization_testing.rb +23 -5
  151. data/test/test_helper.rb +13 -0
  152. metadata +104 -38
  153. data/.rubocop_todo.yml +0 -167
  154. data/docs/ARCHITECTURE.md +0 -126
  155. data/lib/active_model/serializer/include_tree.rb +0 -111
  156. data/lib/active_model_serializers/key_transform.rb +0 -70
  157. data/test/active_model_serializers/key_transform_test.rb +0 -263
  158. data/test/adapter/json_api/relationships_test.rb +0 -199
  159. data/test/include_tree/from_include_args_test.rb +0 -26
  160. data/test/include_tree/from_string_test.rb +0 -94
  161. data/test/include_tree/include_args_to_hash_test.rb +0 -64
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,56 +16,114 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '4.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '4.0'
29
+ version: '4.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: actionpack
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '4.0'
39
+ version: '4.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
47
  - - ">="
39
48
  - !ruby/object:Gem::Version
40
- version: '4.0'
49
+ version: '4.1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: railties
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
57
  - - ">="
46
58
  - !ruby/object:Gem::Version
47
- version: '4.0'
59
+ version: '4.1'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '6'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '4.1'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '6'
73
+ - !ruby/object:Gem::Dependency
74
+ name: jsonapi-renderer
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.1.1.beta1
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
48
83
  type: :runtime
49
84
  prerelease: false
50
85
  version_requirements: !ruby/object:Gem::Requirement
51
86
  requirements:
52
87
  - - ">="
53
88
  - !ruby/object:Gem::Version
54
- version: '4.0'
89
+ version: 0.1.1.beta1
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '0.2'
93
+ - !ruby/object:Gem::Dependency
94
+ name: case_transform
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0.2'
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0.2'
55
107
  - !ruby/object:Gem::Dependency
56
108
  name: activerecord
57
109
  requirement: !ruby/object:Gem::Requirement
58
110
  requirements:
59
111
  - - ">="
60
112
  - !ruby/object:Gem::Version
61
- version: '4.0'
113
+ version: '4.1'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '6'
62
117
  type: :development
63
118
  prerelease: false
64
119
  version_requirements: !ruby/object:Gem::Requirement
65
120
  requirements:
66
121
  - - ">="
67
122
  - !ruby/object:Gem::Version
68
- version: '4.0'
123
+ version: '4.1'
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: '6'
69
127
  - !ruby/object:Gem::Dependency
70
128
  name: kaminari
71
129
  requirement: !ruby/object:Gem::Requirement
@@ -208,10 +266,10 @@ files:
208
266
  - ".github/PULL_REQUEST_TEMPLATE.md"
209
267
  - ".gitignore"
210
268
  - ".rubocop.yml"
211
- - ".rubocop_todo.yml"
212
269
  - ".simplecov"
213
270
  - ".travis.yml"
214
271
  - CHANGELOG.md
272
+ - CODE_OF_CONDUCT.md
215
273
  - CONTRIBUTING.md
216
274
  - Gemfile
217
275
  - MIT-LICENSE
@@ -222,13 +280,13 @@ files:
222
280
  - bin/bench
223
281
  - bin/bench_regression
224
282
  - bin/serve_benchmark
225
- - docs/ARCHITECTURE.md
226
283
  - docs/README.md
227
284
  - docs/STYLE.md
228
285
  - docs/general/adapters.md
229
286
  - docs/general/caching.md
230
287
  - docs/general/configuration_options.md
231
288
  - docs/general/deserialization.md
289
+ - docs/general/fields.md
232
290
  - docs/general/getting_started.md
233
291
  - docs/general/instrumentation.md
234
292
  - docs/general/key_transforms.md
@@ -237,11 +295,14 @@ files:
237
295
  - docs/general/serializers.md
238
296
  - docs/how-open-source-maintained.jpg
239
297
  - docs/howto/add_pagination_links.md
298
+ - docs/howto/add_relationship_links.md
240
299
  - docs/howto/add_root_key.md
300
+ - docs/howto/grape_integration.md
241
301
  - docs/howto/outside_controller_use.md
242
302
  - docs/howto/passing_arbitrary_options.md
243
303
  - docs/howto/serialize_poro.md
244
304
  - docs/howto/test.md
305
+ - docs/howto/upgrade_from_0_8_to_0_10.md
245
306
  - docs/integrations/ember-and-json-api.md
246
307
  - docs/integrations/grape.md
247
308
  - docs/jsonapi/errors.md
@@ -260,28 +321,27 @@ files:
260
321
  - lib/active_model/serializer/adapter/null.rb
261
322
  - lib/active_model/serializer/array_serializer.rb
262
323
  - lib/active_model/serializer/association.rb
263
- - lib/active_model/serializer/associations.rb
264
324
  - lib/active_model/serializer/attribute.rb
265
- - lib/active_model/serializer/attributes.rb
266
325
  - lib/active_model/serializer/belongs_to_reflection.rb
267
- - lib/active_model/serializer/caching.rb
268
326
  - lib/active_model/serializer/collection_reflection.rb
269
327
  - lib/active_model/serializer/collection_serializer.rb
270
- - lib/active_model/serializer/configuration.rb
328
+ - lib/active_model/serializer/concerns/associations.rb
329
+ - lib/active_model/serializer/concerns/attributes.rb
330
+ - lib/active_model/serializer/concerns/caching.rb
331
+ - lib/active_model/serializer/concerns/configuration.rb
332
+ - lib/active_model/serializer/concerns/links.rb
333
+ - lib/active_model/serializer/concerns/meta.rb
334
+ - lib/active_model/serializer/concerns/type.rb
271
335
  - lib/active_model/serializer/error_serializer.rb
272
336
  - lib/active_model/serializer/errors_serializer.rb
273
337
  - lib/active_model/serializer/field.rb
274
338
  - lib/active_model/serializer/fieldset.rb
275
339
  - lib/active_model/serializer/has_many_reflection.rb
276
340
  - lib/active_model/serializer/has_one_reflection.rb
277
- - lib/active_model/serializer/include_tree.rb
278
- - lib/active_model/serializer/links.rb
279
341
  - lib/active_model/serializer/lint.rb
280
- - lib/active_model/serializer/meta.rb
281
342
  - lib/active_model/serializer/null.rb
282
343
  - lib/active_model/serializer/reflection.rb
283
344
  - lib/active_model/serializer/singular_reflection.rb
284
- - lib/active_model/serializer/type.rb
285
345
  - lib/active_model/serializer/version.rb
286
346
  - lib/active_model_serializers.rb
287
347
  - lib/active_model_serializers/adapter.rb
@@ -302,8 +362,8 @@ files:
302
362
  - lib/active_model_serializers/deprecate.rb
303
363
  - lib/active_model_serializers/deserialization.rb
304
364
  - lib/active_model_serializers/json_pointer.rb
305
- - lib/active_model_serializers/key_transform.rb
306
365
  - lib/active_model_serializers/logging.rb
366
+ - lib/active_model_serializers/lookup_chain.rb
307
367
  - lib/active_model_serializers/model.rb
308
368
  - lib/active_model_serializers/railtie.rb
309
369
  - lib/active_model_serializers/register_jsonapi_renderer.rb
@@ -324,21 +384,25 @@ files:
324
384
  - test/action_controller/json/include_test.rb
325
385
  - test/action_controller/json_api/deserialization_test.rb
326
386
  - test/action_controller/json_api/errors_test.rb
387
+ - test/action_controller/json_api/fields_test.rb
327
388
  - test/action_controller/json_api/linked_test.rb
328
389
  - test/action_controller/json_api/pagination_test.rb
329
390
  - test/action_controller/json_api/transform_test.rb
391
+ - test/action_controller/lookup_proc_test.rb
392
+ - test/action_controller/namespace_lookup_test.rb
330
393
  - test/action_controller/serialization_scope_name_test.rb
331
394
  - test/action_controller/serialization_test.rb
332
395
  - test/active_model_serializers/adapter_for_test.rb
333
396
  - test/active_model_serializers/json_pointer_test.rb
334
- - test/active_model_serializers/key_transform_test.rb
335
397
  - test/active_model_serializers/logging_test.rb
336
398
  - test/active_model_serializers/model_test.rb
337
399
  - test/active_model_serializers/railtie_test_isolated.rb
400
+ - test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb
338
401
  - test/active_model_serializers/serialization_context_test_isolated.rb
339
402
  - test/active_model_serializers/test/schema_test.rb
340
403
  - test/active_model_serializers/test/serializer_test.rb
341
404
  - test/active_record_test.rb
405
+ - test/adapter/attributes_test.rb
342
406
  - test/adapter/deprecation_test.rb
343
407
  - test/adapter/json/belongs_to_test.rb
344
408
  - test/adapter/json/collection_test.rb
@@ -352,13 +416,13 @@ files:
352
416
  - test/adapter/json_api/has_many_explicit_serializer_test.rb
353
417
  - test/adapter/json_api/has_many_test.rb
354
418
  - test/adapter/json_api/has_one_test.rb
419
+ - test/adapter/json_api/include_data_if_sideloaded_test.rb
355
420
  - test/adapter/json_api/json_api_test.rb
356
421
  - test/adapter/json_api/linked_test.rb
357
422
  - test/adapter/json_api/links_test.rb
358
423
  - test/adapter/json_api/pagination_links_test.rb
359
424
  - test/adapter/json_api/parse_test.rb
360
425
  - test/adapter/json_api/relationship_test.rb
361
- - test/adapter/json_api/relationships_test.rb
362
426
  - test/adapter/json_api/resource_identifier_test.rb
363
427
  - test/adapter/json_api/resource_meta_test.rb
364
428
  - test/adapter/json_api/toplevel_jsonapi_test.rb
@@ -371,7 +435,10 @@ files:
371
435
  - test/array_serializer_test.rb
372
436
  - test/benchmark/app.rb
373
437
  - test/benchmark/benchmarking_support.rb
438
+ - test/benchmark/bm_active_record.rb
439
+ - test/benchmark/bm_adapter.rb
374
440
  - test/benchmark/bm_caching.rb
441
+ - test/benchmark/bm_lookup_chain.rb
375
442
  - test/benchmark/bm_transform.rb
376
443
  - test/benchmark/config.ru
377
444
  - test/benchmark/controllers.rb
@@ -383,9 +450,6 @@ files:
383
450
  - test/generators/scaffold_controller_generator_test.rb
384
451
  - test/generators/serializer_generator_test.rb
385
452
  - test/grape_test.rb
386
- - test/include_tree/from_include_args_test.rb
387
- - test/include_tree/from_string_test.rb
388
- - test/include_tree/include_args_to_hash_test.rb
389
453
  - test/lint_test.rb
390
454
  - test/logger_test.rb
391
455
  - test/poro_test.rb
@@ -403,6 +467,7 @@ files:
403
467
  - test/serializers/root_test.rb
404
468
  - test/serializers/serialization_test.rb
405
469
  - test/serializers/serializer_for_test.rb
470
+ - test/serializers/serializer_for_with_namespace_test.rb
406
471
  - test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json
407
472
  - test/support/isolated_unit.rb
408
473
  - test/support/rails5_shims.rb
@@ -419,10 +484,7 @@ homepage: https://github.com/rails-api/active_model_serializers
419
484
  licenses:
420
485
  - MIT
421
486
  metadata: {}
422
- post_install_message: |
423
- NOTE: The default key case for the JsonApi adapter has changed to dashed.
424
- See https://github.com/rails-api/active_model_serializers/blob/master/docs/general/key_transforms.md
425
- for more information on configuring this behavior.
487
+ post_install_message:
426
488
  rdoc_options: []
427
489
  require_paths:
428
490
  - lib
@@ -430,7 +492,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
430
492
  requirements:
431
493
  - - ">="
432
494
  - !ruby/object:Gem::Version
433
- version: 2.0.0
495
+ version: '2.1'
434
496
  required_rubygems_version: !ruby/object:Gem::Requirement
435
497
  requirements:
436
498
  - - ">="
@@ -438,7 +500,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
438
500
  version: '0'
439
501
  requirements: []
440
502
  rubyforge_project:
441
- rubygems_version: 2.4.5
503
+ rubygems_version: 2.4.8
442
504
  signing_key:
443
505
  specification_version: 4
444
506
  summary: Conventions-based JSON generation for Rails.
@@ -448,21 +510,25 @@ test_files:
448
510
  - test/action_controller/json/include_test.rb
449
511
  - test/action_controller/json_api/deserialization_test.rb
450
512
  - test/action_controller/json_api/errors_test.rb
513
+ - test/action_controller/json_api/fields_test.rb
451
514
  - test/action_controller/json_api/linked_test.rb
452
515
  - test/action_controller/json_api/pagination_test.rb
453
516
  - test/action_controller/json_api/transform_test.rb
517
+ - test/action_controller/lookup_proc_test.rb
518
+ - test/action_controller/namespace_lookup_test.rb
454
519
  - test/action_controller/serialization_scope_name_test.rb
455
520
  - test/action_controller/serialization_test.rb
456
521
  - test/active_model_serializers/adapter_for_test.rb
457
522
  - test/active_model_serializers/json_pointer_test.rb
458
- - test/active_model_serializers/key_transform_test.rb
459
523
  - test/active_model_serializers/logging_test.rb
460
524
  - test/active_model_serializers/model_test.rb
461
525
  - test/active_model_serializers/railtie_test_isolated.rb
526
+ - test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb
462
527
  - test/active_model_serializers/serialization_context_test_isolated.rb
463
528
  - test/active_model_serializers/test/schema_test.rb
464
529
  - test/active_model_serializers/test/serializer_test.rb
465
530
  - test/active_record_test.rb
531
+ - test/adapter/attributes_test.rb
466
532
  - test/adapter/deprecation_test.rb
467
533
  - test/adapter/json/belongs_to_test.rb
468
534
  - test/adapter/json/collection_test.rb
@@ -476,13 +542,13 @@ test_files:
476
542
  - test/adapter/json_api/has_many_explicit_serializer_test.rb
477
543
  - test/adapter/json_api/has_many_test.rb
478
544
  - test/adapter/json_api/has_one_test.rb
545
+ - test/adapter/json_api/include_data_if_sideloaded_test.rb
479
546
  - test/adapter/json_api/json_api_test.rb
480
547
  - test/adapter/json_api/linked_test.rb
481
548
  - test/adapter/json_api/links_test.rb
482
549
  - test/adapter/json_api/pagination_links_test.rb
483
550
  - test/adapter/json_api/parse_test.rb
484
551
  - test/adapter/json_api/relationship_test.rb
485
- - test/adapter/json_api/relationships_test.rb
486
552
  - test/adapter/json_api/resource_identifier_test.rb
487
553
  - test/adapter/json_api/resource_meta_test.rb
488
554
  - test/adapter/json_api/toplevel_jsonapi_test.rb
@@ -495,7 +561,10 @@ test_files:
495
561
  - test/array_serializer_test.rb
496
562
  - test/benchmark/app.rb
497
563
  - test/benchmark/benchmarking_support.rb
564
+ - test/benchmark/bm_active_record.rb
565
+ - test/benchmark/bm_adapter.rb
498
566
  - test/benchmark/bm_caching.rb
567
+ - test/benchmark/bm_lookup_chain.rb
499
568
  - test/benchmark/bm_transform.rb
500
569
  - test/benchmark/config.ru
501
570
  - test/benchmark/controllers.rb
@@ -507,9 +576,6 @@ test_files:
507
576
  - test/generators/scaffold_controller_generator_test.rb
508
577
  - test/generators/serializer_generator_test.rb
509
578
  - test/grape_test.rb
510
- - test/include_tree/from_include_args_test.rb
511
- - test/include_tree/from_string_test.rb
512
- - test/include_tree/include_args_to_hash_test.rb
513
579
  - test/lint_test.rb
514
580
  - test/logger_test.rb
515
581
  - test/poro_test.rb
@@ -527,6 +593,7 @@ test_files:
527
593
  - test/serializers/root_test.rb
528
594
  - test/serializers/serialization_test.rb
529
595
  - test/serializers/serializer_for_test.rb
596
+ - test/serializers/serializer_for_with_namespace_test.rb
530
597
  - test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json
531
598
  - test/support/isolated_unit.rb
532
599
  - test/support/rails5_shims.rb
@@ -539,4 +606,3 @@ test_files:
539
606
  - test/support/schemas/simple_json_pointers.json
540
607
  - test/support/serialization_testing.rb
541
608
  - test/test_helper.rb
542
- has_rdoc:
data/.rubocop_todo.yml DELETED
@@ -1,167 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2016-03-08 22:29:52 +0100 using RuboCop version 0.37.2.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 2
10
- Lint/HandleExceptions:
11
- Exclude:
12
- - 'Rakefile'
13
-
14
- # Offense count: 2
15
- # Cop supports --auto-correct.
16
- # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
17
- Lint/UnusedMethodArgument:
18
- Exclude:
19
- - 'test/lint_test.rb'
20
-
21
- # Offense count: 4
22
- # Configuration parameters: EnforcedStyle, SupportedStyles.
23
- # SupportedStyles: strict, flexible
24
- Rails/TimeZone:
25
- Exclude:
26
- - 'test/action_controller/serialization_test.rb'
27
- - 'test/serializers/cache_test.rb'
28
-
29
- # Offense count: 16
30
- # Cop supports --auto-correct.
31
- # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
32
- # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
33
- Style/AlignHash:
34
- Exclude:
35
- - 'test/action_controller/json_api/pagination_test.rb'
36
-
37
- # Offense count: 27
38
- # Cop supports --auto-correct.
39
- # Configuration parameters: EnforcedStyle, SupportedStyles.
40
- # SupportedStyles: braces, no_braces, context_dependent
41
- Style/BracesAroundHashParameters:
42
- Exclude:
43
- - 'test/action_controller/adapter_selector_test.rb'
44
- - 'test/action_controller/json_api/pagination_test.rb'
45
- - 'test/adapter/json_api/linked_test.rb'
46
- - 'test/adapter/json_api/pagination_links_test.rb'
47
- - 'test/adapter/null_test.rb'
48
- - 'test/adapter_test.rb'
49
- - 'test/collection_serializer_test.rb'
50
- - 'test/serializable_resource_test.rb'
51
- - 'test/serializers/associations_test.rb'
52
- - 'test/serializers/attributes_test.rb'
53
- - 'test/serializers/root_test.rb'
54
-
55
- # Offense count: 271
56
- # Configuration parameters: EnforcedStyle, SupportedStyles.
57
- # SupportedStyles: nested, compact
58
- Style/ClassAndModuleChildren:
59
- Enabled: false
60
-
61
- # Offense count: 6
62
- # Cop supports --auto-correct.
63
- Style/CommentIndentation:
64
- Exclude:
65
- - 'active_model_serializers.gemspec'
66
-
67
- # Offense count: 1
68
- Style/DoubleNegation:
69
- Exclude:
70
- - 'lib/active_model/serializable_resource.rb'
71
-
72
- # Offense count: 1
73
- # Configuration parameters: MinBodyLength.
74
- Style/GuardClause:
75
- Exclude:
76
- - 'lib/active_model/serializer.rb'
77
-
78
- # Offense count: 58
79
- # Cop supports --auto-correct.
80
- # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
81
- # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
82
- Style/HashSyntax:
83
- Enabled: false
84
-
85
- # Offense count: 4
86
- # Cop supports --auto-correct.
87
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
88
- # SupportedStyles: special_inside_parentheses, consistent, align_brackets
89
- Style/IndentArray:
90
- Enabled: false
91
-
92
- # Offense count: 10
93
- # Cop supports --auto-correct.
94
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
95
- # SupportedStyles: special_inside_parentheses, consistent, align_braces
96
- Style/IndentHash:
97
- Enabled: false
98
-
99
- # Offense count: 1
100
- # Cop supports --auto-correct.
101
- Style/Lambda:
102
- Exclude:
103
- - 'lib/active_model/serializer.rb'
104
-
105
- # Offense count: 1
106
- # Cop supports --auto-correct.
107
- # Configuration parameters: EnforcedStyle, SupportedStyles.
108
- # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
109
- Style/MethodDefParentheses:
110
- Enabled: false
111
-
112
- # Offense count: 1
113
- # Cop supports --auto-correct.
114
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
115
- # SupportedStyles: aligned, indented
116
- Style/MultilineOperationIndentation:
117
- Enabled: false
118
-
119
- # Offense count: 1
120
- # Cop supports --auto-correct.
121
- Style/NegatedIf:
122
- Exclude:
123
- - 'lib/action_controller/serialization.rb'
124
-
125
- # Offense count: 1
126
- # Cop supports --auto-correct.
127
- Style/PerlBackrefs:
128
- Exclude:
129
- - 'test/fixtures/poro.rb'
130
-
131
- # Offense count: 3
132
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
133
- # NamePrefix: is_, has_, have_
134
- # NamePrefixBlacklist: is_, has_, have_
135
- # NameWhitelist: is_a?
136
- Style/PredicateName:
137
- Exclude:
138
- - 'lib/active_model/serializer/associations.rb'
139
- - 'test/action_controller/json_api/linked_test.rb'
140
-
141
- # Offense count: 1
142
- # Cop supports --auto-correct.
143
- Style/RedundantSelf:
144
- Exclude:
145
- - 'test/fixtures/poro.rb'
146
-
147
- # Offense count: 1
148
- # Cop supports --auto-correct.
149
- # Configuration parameters: AllowIfMethodIsEmpty.
150
- Style/SingleLineMethods:
151
- Exclude:
152
- - 'test/serializers/serializer_for_test.rb'
153
-
154
- # Offense count: 4
155
- # Cop supports --auto-correct.
156
- # Configuration parameters: EnforcedStyle, SupportedStyles.
157
- # SupportedStyles: single_quotes, double_quotes
158
- Style/StringLiteralsInInterpolation:
159
- Enabled: false
160
-
161
- # Offense count: 1
162
- # Cop supports --auto-correct.
163
- # Configuration parameters: EnforcedStyle, SupportedStyles.
164
- # SupportedStyles: final_newline, final_blank_line
165
- Style/TrailingBlankLines:
166
- Exclude:
167
- - 'test/adapter/null_test.rb'
data/docs/ARCHITECTURE.md DELETED
@@ -1,126 +0,0 @@
1
- [Back to Guides](README.md)
2
-
3
- This document focuses on architecture the 0.10.x version of ActiveModelSerializers. If you are interested in the architecture of the 0.8 or 0.9 versions,
4
- please refer to the [0.8 README](https://github.com/rails-api/active_model_serializers/blob/0-8-stable/README.md) or
5
- [0.9 README](https://github.com/rails-api/active_model_serializers/blob/0-9-stable/README.md).
6
-
7
- The original design is also available [here](https://github.com/rails-api/active_model_serializers/blob/d72b66d4c5355b0ff0a75a04895fcc4ea5b0c65e/README.textile).
8
-
9
- # ARCHITECTURE
10
-
11
- An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serialization.rb)
12
- and exposes an `attributes` method, among a few others.
13
- It allows you to specify which attributes and associations should be represented in the serializatation of the resource.
14
- It requires an adapter to transform its attributes into a JSON document; it cannot be serialized itself.
15
- It may be useful to think of it as a
16
- [presenter](http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
17
-
18
- The **`ActiveModel::ArraySerializer`** represent a collection of resources as serializers
19
- and, if there is no serializer, primitives.
20
-
21
- The **`ActiveModel::Adapter`** describes the structure of the JSON document generated from a
22
- serializer. For example, the `Attributes` example represents each serializer as its
23
- unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
24
- API](http://jsonapi.org/) document.
25
-
26
- The **`ActiveModelSerializers::SerializableResource`** acts to coordinate the serializer(s) and adapter
27
- to an object that responds to `to_json`, and `as_json`. It is used in the controller to
28
- encapsulate the serialization resource when rendered. However, it can also be used on its own
29
- to serialize a resource outside of a controller, as well.
30
-
31
- ## Primitive handling
32
-
33
- Definitions: A primitive is usually a String or Array. There is no serializer
34
- defined for them; they will be serialized when the resource is converted to JSON (`as_json` or
35
- `to_json`). (The below also applies for any object with no serializer.)
36
-
37
- ActiveModelSerializers doesn't handle primitives passed to `render json:` at all.
38
-
39
- However, when a primitive value is an attribute or in a collection,
40
- it is not modified.
41
-
42
- Internally, if no serializer can be found in the controller, the resource is not decorated by
43
- ActiveModelSerializers.
44
-
45
- If the collection serializer (ArraySerializer) cannot
46
- identify a serializer for a resource in its collection, it raises [`NoSerializerError`](https://github.com/rails-api/active_model_serializers/issues/1191#issuecomment-142327128)
47
- which is rescued in `ActiveModel::Serializer::Reflection#build_association` which sets
48
- the association value directly:
49
-
50
- ```ruby
51
- reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
52
- ```
53
-
54
- (which is called by the adapter as `serializer.associations(*)`.)
55
-
56
- ## How options are parsed
57
-
58
- High-level overview:
59
-
60
- - For a collection
61
- - `:serializer` specifies the collection serializer and
62
- - `:each_serializer` specifies the serializer for each resource in the collection.
63
- - For a single resource, the `:serializer` option is the resource serializer.
64
- - Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
65
- [`ADAPTER_OPTION_KEYS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/serializable_resource.rb#L5).
66
- The remaining options are serializer options.
67
-
68
- Details:
69
-
70
- 1. **ActionController::Serialization**
71
- 1. `serializable_resource = ActiveModelSerializers::SerializableResource.new(resource, options)`
72
- 1. `options` are partitioned into `adapter_opts` and everything else (`serializer_opts`).
73
- The `adapter_opts` keys are defined in `ActiveModelSerializers::SerializableResource::ADAPTER_OPTION_KEYS`.
74
- 1. **ActiveModelSerializers::SerializableResource**
75
- 1. `if serializable_resource.serializer?` (there is a serializer for the resource, and an adapter is used.)
76
- - Where `serializer?` is `use_adapter? && !!(serializer)`
77
- - Where `use_adapter?`: 'True when no explicit adapter given, or explicit value is truthy (non-nil);
78
- False when explicit adapter is falsy (nil or false)'
79
- - Where `serializer`:
80
- 1. from explicit `:serializer` option, else
81
- 2. implicitly from resource `ActiveModel::Serializer.serializer_for(resource)`
82
- 1. A side-effect of checking `serializer` is:
83
- - The `:serializer` option is removed from the serializer_opts hash
84
- - If the `:each_serializer` option is present, it is removed from the serializer_opts hash and set as the `:serializer` option
85
- 1. The serializer and adapter are created as
86
- 1. `serializer_instance = serializer.new(resource, serializer_opts)`
87
- 2. `adapter_instance = ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)`
88
- 1. **ActiveModel::Serializer::ArraySerializer#new**
89
- 1. If the `serializer_instance` was a `ArraySerializer` and the `:serializer` serializer_opts
90
- 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).
91
- 1. **ActiveModel::Serializer#attributes** is used by the adapter to get the attributes for
92
- resource as defined by the serializer.
93
-
94
- ## What does a 'serializable resource' look like?
95
-
96
- - An `ActiveRecord::Base` object.
97
- - Any Ruby object that passes the
98
- [Lint](http://www.rubydoc.info/github/rails-api/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
99
- [code](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/lint.rb).
100
-
101
- ActiveModelSerializers provides a
102
- [`ActiveModelSerializers::Model`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/model.rb),
103
- which is a simple serializable PORO (Plain-Old Ruby Object).
104
-
105
- ActiveModelSerializers::Model may be used either as a template, or in production code.
106
-
107
- ```ruby
108
- class MyModel < ActiveModelSerializers::Model
109
- attr_accessor :id, :name, :level
110
- end
111
- ```
112
-
113
- The default serializer for `MyModel` would be `MyModelSerializer` whether MyModel is an
114
- ActiveRecord::Base object or not.
115
-
116
- Outside of the controller the rules are **exactly** the same as for records. For example:
117
-
118
- ```ruby
119
- render json: MyModel.new(level: 'awesome'), adapter: :json
120
- ```
121
-
122
- would be serialized the same as
123
-
124
- ```ruby
125
- ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'), adapter: :json).as_json
126
- ```