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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb97c8740c2530c085ee9186ea27ddd220367fc3
4
- data.tar.gz: 0a768d3ab122abe2c3e7f5b6c00a8dada6872433
3
+ metadata.gz: e38c0b5ccb4d32da05808ebff7112d20d7d8d451
4
+ data.tar.gz: 7e50bf4858b40a9f988d112a95f6afc34c38156b
5
5
  SHA512:
6
- metadata.gz: 5589022dd6fa160c0a03981cedf46433fb1eb19e4bac5f3489908671e9e0969c48bb7a86cf03d12cf8ce825b2efe3ed6ad1b6594019635470319c899e7964617
7
- data.tar.gz: 989cf413780f12d47a553a7aae5cba33de1625bbc022366b7e4533810b87b151302ed6000116c03234bf2b2048a913048624728a54be87cead848076924cf6ce
6
+ metadata.gz: 25710e210284167d23ebf77b024d31b06326d71a68c8bcbc1f4f4439baf0b50018a02060da44ebefcb077c9abc2a74bd632cb54662942cb3d17c464d2b420b79
7
+ data.tar.gz: 712546ebd0b8fd5d1243b32c76349fc92ab0610e2562848c42c7faff4e1fc5820282ea1492c5526d721137fda7eb6dc1dacc422720f493d36e75c9185c3bff79
data/.rubocop.yml CHANGED
@@ -1,7 +1,5 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  AllCops:
4
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.1
5
3
  Exclude:
6
4
  - config/initializers/forbidden_yaml.rb
7
5
  - !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
@@ -46,7 +44,7 @@ Style/AlignParameters:
46
44
  EnforcedStyle: with_fixed_indentation
47
45
 
48
46
  Style/ClassAndModuleChildren:
49
- EnforcedStyle: compact
47
+ EnforcedStyle: nested
50
48
 
51
49
  Style/Documentation:
52
50
  Enabled: false
data/.travis.yml CHANGED
@@ -4,15 +4,19 @@ sudo: false
4
4
 
5
5
  rvm:
6
6
  - 2.1
7
- - 2.2.3
8
- - 2.3.0
7
+ - 2.2.6
8
+ - 2.3.3
9
9
  - ruby-head
10
- - jruby-9.0.4.0
10
+ - jruby-9.1.5.0 # is precompiled per http://rubies.travis-ci.org/
11
11
  - jruby-head
12
12
 
13
13
  jdk:
14
14
  - oraclejdk8
15
15
 
16
+ before_install:
17
+ - gem update --system
18
+ - rvm @global do gem uninstall bundler -a -x
19
+ - rvm @global do gem install bundler -v 1.13.7
16
20
  install: bundle install --path=vendor/bundle --retry=3 --jobs=3
17
21
  cache:
18
22
  directories:
@@ -20,23 +24,31 @@ cache:
20
24
 
21
25
  script:
22
26
  - bundle exec rake ci
23
-
27
+ after_success:
28
+ - codeclimate-test-reporter
24
29
  env:
25
30
  global:
26
31
  - "JRUBY_OPTS='--dev -J-Xmx1024M --debug'"
27
32
  matrix:
28
33
  - "RAILS_VERSION=4.1"
29
34
  - "RAILS_VERSION=4.2"
35
+ - "RAILS_VERSION=5.0"
30
36
  - "RAILS_VERSION=master"
31
37
 
32
38
  matrix:
33
39
  exclude:
34
40
  - rvm: 2.1
35
41
  env: RAILS_VERSION=master
36
- - rvm: jruby-9.0.4.0
42
+ - rvm: jruby-9.1.5.0
37
43
  env: RAILS_VERSION=master
38
44
  - rvm: jruby-head
39
45
  env: RAILS_VERSION=master
46
+ - rvm: 2.1
47
+ env: RAILS_VERSION=5.0
48
+ - rvm: jruby-9.1.5.0
49
+ env: RAILS_VERSION=5.0
50
+ - rvm: jruby-head
51
+ env: RAILS_VERSION=5.0
40
52
  allow_failures:
41
53
  - rvm: ruby-head
42
54
  - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -1,8 +1,117 @@
1
1
  ## 0.10.x
2
2
 
3
- ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.0...master)
3
+ ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...master)
4
4
 
5
- ### v0.10.0 (2016-05-17)
5
+ Breaking changes:
6
+
7
+ Features:
8
+
9
+ Fixes:
10
+
11
+ Misc:
12
+
13
+ ### [v0.10.5 (2017-03-07)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...v0.10.5)
14
+
15
+ Breaking changes:
16
+
17
+ Features:
18
+
19
+ - [#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)
20
+ - [#2057](https://github.com/rails-api/active_model_serializers/pull/2057)
21
+ Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.2']`
22
+ (@jaredbeck)
23
+
24
+ Fixes:
25
+
26
+ - [#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)
27
+
28
+ Misc:
29
+
30
+ - [#2055](https://github.com/rails-api/active_model_serializers/pull/2055)
31
+ Replace deprecated dependency jsonapi with jsonapi-renderer. (@jaredbeck)
32
+ - [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) Make test attributes explicit. Tests have Model#associations. (@bf4)
33
+ - [#1981](https://github.com/rails-api/active_model_serializers/pull/1981) Fix relationship link documentation. (@groyoh)
34
+ - [#2035](https://github.com/rails-api/active_model_serializers/pull/2035) Document how to disable the logger. (@MSathieu)
35
+ - [#2039](https://github.com/rails-api/active_model_serializers/pull/2039) Documentation fixes. (@biow0lf)
36
+
37
+ ### [v0.10.4 (2017-01-06)](https://github.com/rails-api/active_model_serializers/compare/v0.10.3...v0.10.4)
38
+
39
+ Misc:
40
+
41
+ - [#2005](https://github.com/rails-api/active_model_serializers/pull/2005) Update jsonapi runtime dependency to 0.1.1.beta6, support Ruby 2.4. (@kofronpi)
42
+ - [#1993](https://github.com/rails-api/active_model_serializers/pull/1993) Swap out KeyTransform for CaseTransform gem for the possibility of native extension use. (@NullVoxPopuli)
43
+
44
+ ### [v0.10.3 (2016-11-21)](https://github.com/rails-api/active_model_serializers/compare/v0.10.2...v0.10.3)
45
+
46
+ Fixes:
47
+
48
+ - [#1973](https://github.com/rails-api/active_model_serializers/pull/1973) Fix namespace lookup for collections and has_many relationships (@groyoh)
49
+ - [#1887](https://github.com/rails-api/active_model_serializers/pull/1887) Make the comment reflect what the function does (@johnnymo87)
50
+ - [#1890](https://github.com/rails-api/active_model_serializers/issues/1890) Ensure generator inherits from ApplicationSerializer when available (@richmolj)
51
+ - [#1922](https://github.com/rails-api/active_model_serializers/pull/1922) Make railtie an optional dependency in runtime (@ggpasqualino)
52
+ - [#1930](https://github.com/rails-api/active_model_serializers/pull/1930) Ensure valid jsonapi when relationship has no links or data (@richmolj)
53
+
54
+ Features:
55
+
56
+ - [#1757](https://github.com/rails-api/active_model_serializers/pull/1757) Make serializer lookup chain configurable. (@NullVoxPopuli)
57
+ - [#1968](https://github.com/rails-api/active_model_serializers/pull/1968) (@NullVoxPopuli)
58
+ - Add controller namespace to default controller lookup
59
+ - Provide a `namespace` render option
60
+ - document how set the namespace in the controller for implicit lookup.
61
+ - [#1791](https://github.com/rails-api/active_model_serializers/pull/1791) (@bf4, @youroff, @NullVoxPopuli)
62
+ - Added `jsonapi_namespace_separator` config option.
63
+ - [#1889](https://github.com/rails-api/active_model_serializers/pull/1889) Support key transformation for Attributes adapter (@iancanderson, @danbee)
64
+ - [#1917](https://github.com/rails-api/active_model_serializers/pull/1917) Add `jsonapi_pagination_links_enabled` configuration option (@richmolj)
65
+ - [#1797](https://github.com/rails-api/active_model_serializers/pull/1797) Only include 'relationships' when sideloading (@richmolj)
66
+
67
+ Fixes:
68
+
69
+ - [#1833](https://github.com/rails-api/active_model_serializers/pull/1833) Remove relationship links if they are null (@groyoh)
70
+ - [#1881](https://github.com/rails-api/active_model_serializers/pull/1881) ActiveModelSerializers::Model correctly works with string keys (@yevhene)
71
+
72
+ Misc:
73
+ - [#1767](https://github.com/rails-api/active_model_serializers/pull/1767) Replace raising/rescuing `CollectionSerializer::NoSerializerError`,
74
+ throw/catch `:no_serializer`. (@bf4)
75
+ - [#1839](https://github.com/rails-api/active_model_serializers/pull/1839) `fields` tests demonstrating usage for both attributes and relationships. (@NullVoxPopuli)
76
+ - [#1812](https://github.com/rails-api/active_model_serializers/pull/1812) add a code of conduct (@corainchicago)
77
+
78
+ - [#1878](https://github.com/rails-api/active_model_serializers/pull/1878) Cache key generation for serializers now uses `ActiveSupport::Cache.expand_cache_key` instead of `Array#join` by default and is also overridable. This change should be backward-compatible. (@markiz)
79
+
80
+ - [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka)
81
+ - [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli)
82
+ - [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono)
83
+ - [#1967](https://github.com/rails-api/active_model_serializers/pull/1967) Improve type method documentation. (@yukideluxe)
84
+
85
+ ### [v0.10.2 (2016-07-05)](https://github.com/rails-api/active_model_serializers/compare/v0.10.1...v0.10.2)
86
+
87
+ Fixes:
88
+ - [#1814](https://github.com/rails-api/active_model_serializers/pull/1814) Ensuring read_multi works with fragment cache
89
+ - [#1848](https://github.com/rails-api/active_model_serializers/pull/1848) Redefine associations on inherited serializers. (@EhsanYousefi)
90
+
91
+ Misc:
92
+ - [#1808](https://github.com/rails-api/active_model_serializers/pull/1808) Adds documentation for `fields` option. (@luizkowalski)
93
+
94
+ ### [v0.10.1 (2016-06-16)](https://github.com/rails-api/active_model_serializers/compare/v0.10.0...v0.10.1)
95
+
96
+ Features:
97
+ - [#1668](https://github.com/rails-api/active_model_serializers/pull/1668) Exclude nil and empty links. (@sigmike)
98
+ - [#1426](https://github.com/rails-api/active_model_serializers/pull/1426) Add ActiveModelSerializers.config.default_includes (@empact)
99
+
100
+ Fixes:
101
+ - [#1754](https://github.com/rails-api/active_model_serializers/pull/1754) Fixes #1759, Grape integration, improves serialization_context
102
+ missing error message on pagination. Document overriding CollectionSerializer#paginated?. (@bf4)
103
+ Moved serialization_context creation to Grape formatter, so resource serialization works without explicit calls to the `render` helper method.
104
+ Added Grape collection tests. (@onomated)
105
+ - [#1287](https://github.com/rails-api/active_model_serializers/pull/1287) Pass `fields` options from adapter to serializer. (@vasilakisfil)
106
+ - [#1710](https://github.com/rails-api/active_model_serializers/pull/1710) Prevent association loading when `include_data` option
107
+ is set to `false`. (@groyoh)
108
+ - [#1747](https://github.com/rails-api/active_model_serializers/pull/1747) Improve jsonapi mime type registration for Rails 5 (@remear)
109
+
110
+ Misc:
111
+ - [#1734](https://github.com/rails-api/active_model_serializers/pull/1734) Adds documentation for conditional attribute (@lambda2)
112
+ - [#1685](https://github.com/rails-api/active_model_serializers/pull/1685) Replace `IncludeTree` with `IncludeDirective` from the jsonapi gem.
113
+
114
+ ### [v0.10.0 (2016-05-17)](https://github.com/rails-api/active_model_serializers/compare/4a2d9853ba7...v0.10.0)
6
115
 
7
116
  Breaking changes:
8
117
  - [#1662](https://github.com/rails-api/active_model_serializers/pull/1662) Drop support for Rails 4.0 and Ruby 2.0.0. (@remear)
@@ -22,6 +131,7 @@ Fixes:
22
131
 
23
132
  Misc:
24
133
  - [#1673](https://github.com/rails-api/active_model_serializers/pull/1673) Adds "How to" guide on using AMS with POROs (@DrSayre)
134
+ - [#1730](https://github.com/rails-api/active_model_serializers/pull/1730) Adds documentation for overriding default serializer based on conditions (@groyoh/@cgmckeever)
25
135
 
26
136
  ### [v0.10.0.rc5 (2016-04-04)](https://github.com/rails-api/active_model_serializers/compare/v0.10.0.rc4...v0.10.0.rc5)
27
137
 
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting one of the owners listed at https://rubygems.org/gems/active_model_serializers. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -38,16 +38,19 @@ gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
38
38
 
39
39
  group :bench do
40
40
  # https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76
41
- gem 'benchmark-ips', require: false, group: :development
41
+ gem 'benchmark-ips', '>= 2.7.2', require: false, group: :development
42
42
  end
43
43
 
44
44
  group :test do
45
45
  gem 'sqlite3', platform: (@windows_platforms + [:ruby])
46
46
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
47
47
  gem 'codeclimate-test-reporter', require: false
48
+ gem 'm', '~> 1.5'
49
+ gem 'pry', '~> 0.10'
50
+ gem 'pry-byebug', '~> 3.4', platform: :ruby
48
51
  end
49
52
 
50
53
  group :development, :test do
51
- gem 'rubocop', '~> 0.39.0', require: false
54
+ gem 'rubocop', '~> 0.40.0', require: false
52
55
  gem 'yard', require: false
53
56
  end
data/README.md CHANGED
@@ -24,17 +24,6 @@
24
24
  </tr>
25
25
  </table>
26
26
 
27
-
28
- ## Documentation
29
-
30
- - [0.10 (master) Documentation](https://github.com/rails-api/active_model_serializers/tree/master)
31
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/v0.10.0)
32
- - [Guides](docs)
33
- - [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
34
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-9-stable)
35
- - [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
36
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-8-stable)
37
-
38
27
  ## About
39
28
 
40
29
  ActiveModelSerializers brings convention over configuration to your JSON generation.
@@ -50,33 +39,24 @@ resource serialization. The serialization has the `#as_json`, `#to_json` and `#s
50
39
  methods used by the Rails JSON Renderer. (SerializableResource actually delegates
51
40
  these methods to the adapter.)
52
41
 
53
- By default ActiveModelSerializers will use the **Attributes Adapter**.
42
+ By default ActiveModelSerializers will use the **Attributes Adapter** (no JSON root).
54
43
  But we strongly advise you to use **JsonApi Adapter**, which
55
44
  follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
56
45
  Check how to change the adapter in the sections below.
57
46
 
58
- ## RELEASE CANDIDATE, PLEASE READ
59
-
60
- This is the **master** branch of ActiveModelSerializers.
61
-
62
- It will become the `0.10.0` release when it's ready. Currently this is a release candidate.
63
-
64
47
  `0.10.x` is **not** backward compatible with `0.9.x` nor `0.8.x`.
65
48
 
66
- `0.10.x` will be based on the `0.8.0` code, but with a more flexible
49
+ `0.10.x` is based on the `0.8.0` code, but with a more flexible
67
50
  architecture. We'd love your help. [Learn how you can help here.](CONTRIBUTING.md)
68
51
 
69
52
  It is generally safe and recommended to use the master branch.
70
53
 
71
- For more information, see the post '[The future of
72
- AMS](https://medium.com/@joaomdmoura/the-future-of-ams-e5f9047ca7e9)'.
73
-
74
54
  ## Installation
75
55
 
76
56
  Add this line to your application's Gemfile:
77
57
 
78
58
  ```
79
- gem 'active_model_serializers'
59
+ gem 'active_model_serializers', '~> 0.10.0'
80
60
  ```
81
61
 
82
62
  And then execute:
@@ -103,8 +83,30 @@ If you'd like to chat, we have a [community slack](http://amserializers.herokuap
103
83
 
104
84
  Thanks!
105
85
 
86
+ ## Documentation
87
+
88
+ If you're reading this at https://github.com/rails-api/active_model_serializers you are
89
+ reading documentation for our `master`, which may include features that have not
90
+ been released yet. Please see below for the documentation relevant to you.
91
+
92
+ - [0.10 (master) Documentation](https://github.com/rails-api/active_model_serializers/tree/master)
93
+ - [0.10.4 (latest release) Documentation](https://github.com/rails-api/active_model_serializers/tree/v0.10.4)
94
+ - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/active_model_serializers/0.10.4)
95
+ - [Guides](docs)
96
+ - [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)
98
+ - [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)
100
+
101
+
106
102
  ## High-level behavior
107
103
 
104
+ Choose an adapter from [adapters](lib/active_model_serializers/adapter):
105
+
106
+ ``` ruby
107
+ ActiveModelSerializers.config.adapter = :json_api # Default: `:attributes`
108
+ ```
109
+
108
110
  Given a [serializable model](lib/active_model/serializer/lint.rb):
109
111
 
110
112
  ```ruby
@@ -114,7 +116,7 @@ class SomeResource < ActiveRecord::Base
114
116
  end
115
117
  # or
116
118
  class SomeResource < ActiveModelSerializers::Model
117
- attr_accessor :title, :body
119
+ attributes :title, :body
118
120
  end
119
121
  ```
120
122
 
@@ -160,8 +162,146 @@ serializer = SomeSerializer.new(resource, serializer_options)
160
162
  serializer.attributes
161
163
  serializer.associations
162
164
  ```
163
- See [ARCHITECTURE.md](docs/ARCHITECTURE.md) for more information.
164
165
 
165
- # Contributing
166
+ ## Architecture
167
+
168
+ This section 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,
169
+ please refer to the [0.8 README](https://github.com/rails-api/active_model_serializers/blob/0-8-stable/README.md) or
170
+ [0.9 README](https://github.com/rails-api/active_model_serializers/blob/0-9-stable/README.md).
171
+
172
+ The original design is also available [here](https://github.com/rails-api/active_model_serializers/blob/d72b66d4c5355b0ff0a75a04895fcc4ea5b0c65e/README.textile).
173
+
174
+ ### ActiveModel::Serializer
175
+
176
+ An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serialization.rb)
177
+ and exposes an `attributes` method, among a few others.
178
+ It allows you to specify which attributes and associations should be represented in the serializatation of the resource.
179
+ It requires an adapter to transform its attributes into a JSON document; it cannot be serialized itself.
180
+ It may be useful to think of it as a
181
+ [presenter](http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
182
+
183
+ #### ActiveModel::CollectionSerializer
184
+
185
+ The **`ActiveModel::CollectionSerializer`** represents a collection of resources as serializers
186
+ and, if there is no serializer, primitives.
187
+
188
+ ### ActiveModelSerializers::Adapter::Base
189
+
190
+ The **`ActiveModelSerializeres::Adapter::Base`** describes the structure of the JSON document generated from a
191
+ serializer. For example, the `Attributes` example represents each serializer as its
192
+ unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
193
+ API](http://jsonapi.org/) document.
194
+
195
+ ### ActiveModelSerializers::SerializableResource
196
+
197
+ The **`ActiveModelSerializers::SerializableResource`** acts to coordinate the serializer(s) and adapter
198
+ to an object that responds to `to_json`, and `as_json`. It is used in the controller to
199
+ encapsulate the serialization resource when rendered. However, it can also be used on its own
200
+ to serialize a resource outside of a controller, as well.
201
+
202
+ ### Primitive handling
203
+
204
+ Definitions: A primitive is usually a String or Array. There is no serializer
205
+ defined for them; they will be serialized when the resource is converted to JSON (`as_json` or
206
+ `to_json`). (The below also applies for any object with no serializer.)
207
+
208
+ - ActiveModelSerializers doesn't handle primitives passed to `render json:` at all.
209
+
210
+ Internally, if no serializer can be found in the controller, the resource is not decorated by
211
+ ActiveModelSerializers.
212
+
213
+ - However, when a primitive value is an attribute or in a collection, it is not modified.
214
+
215
+ When serializing a collection and the collection serializer (CollectionSerializer) cannot
216
+ identify a serializer for a resource in its collection, it throws [`:no_serializer`](https://github.com/rails-api/active_model_serializers/issues/1191#issuecomment-142327128).
217
+ For example, when caught by `Reflection#build_association`, and the association value is set directly:
218
+
219
+ ```ruby
220
+ reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
221
+ ```
222
+
223
+ (which is called by the adapter as `serializer.associations(*)`.)
224
+
225
+ ### How options are parsed
226
+
227
+ High-level overview:
228
+
229
+ - For a **collection**
230
+ - `:serializer` specifies the collection serializer and
231
+ - `:each_serializer` specifies the serializer for each resource in the collection.
232
+ - For a **single resource**, the `:serializer` option is the resource serializer.
233
+ - 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).
235
+ The remaining options are serializer options.
236
+
237
+ Details:
238
+
239
+ 1. **ActionController::Serialization**
240
+ 1. `serializable_resource = ActiveModelSerializers::SerializableResource.new(resource, options)`
241
+ 1. `options` are partitioned into `adapter_opts` and everything else (`serializer_opts`).
242
+ The `adapter_opts` keys are defined in [`ActiveModelSerializers::SerializableResource::ADAPTER_OPTION_KEYS`](lib/active_model_serializers/serializable_resource.rb#L5).
243
+ 1. **ActiveModelSerializers::SerializableResource**
244
+ 1. `if serializable_resource.serializer?` (there is a serializer for the resource, and an adapter is used.)
245
+ - Where `serializer?` is `use_adapter? && !!(serializer)`
246
+ - Where `use_adapter?`: 'True when no explicit adapter given, or explicit value is truthy (non-nil);
247
+ False when explicit adapter is falsy (nil or false)'
248
+ - Where `serializer`:
249
+ 1. from explicit `:serializer` option, else
250
+ 2. implicitly from resource `ActiveModel::Serializer.serializer_for(resource)`
251
+ 1. A side-effect of checking `serializer` is:
252
+ - The `:serializer` option is removed from the serializer_opts hash
253
+ - If the `:each_serializer` option is present, it is removed from the serializer_opts hash and set as the `:serializer` option
254
+ 1. The serializer and adapter are created as
255
+ 1. `serializer_instance = serializer.new(resource, serializer_opts)`
256
+ 2. `adapter_instance = ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)`
257
+ 1. **ActiveModel::Serializer::CollectionSerializer#new**
258
+ 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).
260
+ 1. **ActiveModel::Serializer#attributes** is used by the adapter to get the attributes for
261
+ resource as defined by the serializer.
262
+
263
+ (In Rails, the `options` are also passed to the `as_json(options)` or `to_json(options)`
264
+ methods on the resource serialization by the Rails JSON renderer. They are, therefore, important
265
+ to know about, but not part of ActiveModelSerializers.)
266
+
267
+ ### What does a 'serializable resource' look like?
268
+
269
+ - An `ActiveRecord::Base` object.
270
+ - 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).
273
+
274
+ ActiveModelSerializers provides a
275
+ [`ActiveModelSerializers::Model`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/model.rb),
276
+ which is a simple serializable PORO (Plain-Old Ruby Object).
277
+
278
+ `ActiveModelSerializers::Model` may be used either as a reference implementation, or in production code.
279
+
280
+ ```ruby
281
+ class MyModel < ActiveModelSerializers::Model
282
+ attributes :id, :name, :level
283
+ end
284
+ ```
285
+
286
+ The default serializer for `MyModel` would be `MyModelSerializer` whether MyModel is an
287
+ ActiveRecord::Base object or not.
288
+
289
+ Outside of the controller the rules are **exactly** the same as for records. For example:
290
+
291
+ ```ruby
292
+ render json: MyModel.new(level: 'awesome'), adapter: :json
293
+ ```
294
+
295
+ would be serialized the same as
296
+
297
+ ```ruby
298
+ ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'), adapter: :json).as_json
299
+ ```
300
+
301
+ ## Semantic Versioning
302
+
303
+ This project adheres to [semver](http://semver.org/)
304
+
305
+ ## Contributing
166
306
 
167
307
  See [CONTRIBUTING.md](CONTRIBUTING.md)
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ rescue LoadError
5
5
  end
6
6
  begin
7
7
  require 'simplecov'
8
- rescue LoadError
8
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
9
9
  end
10
10
 
11
11
  Bundler::GemHelper.install_tasks
@@ -33,7 +33,7 @@ end
33
33
  begin
34
34
  require 'rubocop'
35
35
  require 'rubocop/rake_task'
36
- rescue LoadError
36
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
37
37
  else
38
38
  Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
39
39
  require 'rbconfig'
@@ -100,4 +100,4 @@ else
100
100
  end
101
101
 
102
102
  desc 'CI test task'
103
- task :ci => [:default]
103
+ task ci: [:default]
@@ -19,33 +19,36 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
  spec.executables = []
21
21
 
22
- spec.required_ruby_version = '>= 2.0.0'
22
+ spec.required_ruby_version = '>= 2.1'
23
23
 
24
- rails_versions = '>= 4.0'
24
+ rails_versions = ['>= 4.1', '< 6']
25
25
  spec.add_runtime_dependency 'activemodel', rails_versions
26
- # 'activesupport', rails_versions
27
- # 'builder'
26
+ # 'activesupport', rails_versions
27
+ # 'builder'
28
28
 
29
29
  spec.add_runtime_dependency 'actionpack', rails_versions
30
- # 'activesupport', rails_versions
31
- # 'rack'
32
- # 'rack-test', '~> 0.6.2'
30
+ # 'activesupport', rails_versions
31
+ # 'rack'
32
+ # 'rack-test', '~> 0.6.2'
33
33
 
34
- spec.add_runtime_dependency 'railties', rails_versions
35
- # 'activesupport', rails_versions
36
- # 'actionpack', rails_versions
37
- # 'rake', '>= 0.8.7'
34
+ spec.add_development_dependency 'railties', rails_versions
35
+ # 'activesupport', rails_versions
36
+ # 'actionpack', rails_versions
37
+ # 'rake', '>= 0.8.7'
38
38
 
39
39
  # 'activesupport', rails_versions
40
- # 'i18n,
41
- # 'tzinfo'
42
- # 'minitest'
43
- # 'thread_safe'
40
+ # 'i18n,
41
+ # 'tzinfo'
42
+ # 'minitest'
43
+ # 'thread_safe'
44
+
45
+ spec.add_runtime_dependency 'jsonapi-renderer', ['>= 0.1.1.beta1', '< 0.2']
46
+ spec.add_runtime_dependency 'case_transform', '>= 0.2'
44
47
 
45
48
  spec.add_development_dependency 'activerecord', rails_versions
46
- # arel
47
- # activesupport
48
- # activemodel
49
+ # arel
50
+ # activesupport
51
+ # activemodel
49
52
 
50
53
  # Soft dependency for pagination
51
54
  spec.add_development_dependency 'kaminari', ' ~> 0.16.3'
@@ -57,10 +60,4 @@ Gem::Specification.new do |spec|
57
60
  spec.add_development_dependency 'grape', ['>= 0.13', '< 1.0']
58
61
  spec.add_development_dependency 'json_schema'
59
62
  spec.add_development_dependency 'rake', ['>= 10.0', '< 12.0']
60
-
61
- spec.post_install_message = <<-EOF
62
- NOTE: The default key case for the JsonApi adapter has changed to dashed.
63
- See https://github.com/rails-api/active_model_serializers/blob/master/docs/general/key_transforms.md
64
- for more information on configuring this behavior.
65
- EOF
66
63
  end