active_model_serializers 0.10.0.rc4 → 0.10.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +29 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +15 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +19 -1
- data/.rubocop_todo.yml +30 -103
- data/.simplecov +0 -1
- data/.travis.yml +20 -8
- data/CHANGELOG.md +89 -5
- data/CONTRIBUTING.md +54 -179
- data/Gemfile +7 -2
- data/{LICENSE.txt → MIT-LICENSE} +0 -0
- data/README.md +27 -5
- data/Rakefile +44 -16
- data/active_model_serializers.gemspec +9 -1
- data/appveyor.yml +1 -0
- data/bin/bench +171 -0
- data/bin/bench_regression +316 -0
- data/bin/serve_benchmark +39 -0
- data/docs/ARCHITECTURE.md +13 -7
- data/docs/README.md +5 -1
- data/docs/STYLE.md +58 -0
- data/docs/general/adapters.md +99 -16
- data/docs/general/configuration_options.md +87 -14
- data/docs/general/deserialization.md +100 -0
- data/docs/general/getting_started.md +35 -0
- data/docs/general/instrumentation.md +1 -1
- data/docs/general/key_transforms.md +40 -0
- data/docs/general/rendering.md +115 -13
- data/docs/general/serializers.md +138 -6
- data/docs/howto/add_pagination_links.md +36 -18
- data/docs/howto/outside_controller_use.md +4 -4
- data/docs/howto/passing_arbitrary_options.md +27 -0
- data/docs/jsonapi/errors.md +56 -0
- data/docs/jsonapi/schema.md +29 -18
- data/docs/rfcs/0000-namespace.md +106 -0
- data/docs/rfcs/template.md +15 -0
- data/lib/action_controller/serialization.rb +10 -19
- data/lib/active_model/serializable_resource.rb +4 -65
- data/lib/active_model/serializer.rb +73 -18
- data/lib/active_model/serializer/adapter.rb +15 -82
- data/lib/active_model/serializer/adapter/attributes.rb +5 -56
- data/lib/active_model/serializer/adapter/base.rb +5 -47
- data/lib/active_model/serializer/adapter/json.rb +6 -12
- data/lib/active_model/serializer/adapter/json_api.rb +5 -213
- data/lib/active_model/serializer/adapter/null.rb +7 -3
- data/lib/active_model/serializer/array_serializer.rb +3 -3
- data/lib/active_model/serializer/association.rb +4 -5
- data/lib/active_model/serializer/attributes.rb +1 -1
- data/lib/active_model/serializer/caching.rb +56 -5
- data/lib/active_model/serializer/collection_serializer.rb +30 -13
- data/lib/active_model/serializer/configuration.rb +7 -0
- data/lib/active_model/serializer/error_serializer.rb +10 -0
- data/lib/active_model/serializer/errors_serializer.rb +27 -0
- data/lib/active_model/serializer/links.rb +4 -2
- data/lib/active_model/serializer/lint.rb +14 -0
- data/lib/active_model/serializer/meta.rb +29 -0
- data/lib/active_model/serializer/null.rb +17 -0
- data/lib/active_model/serializer/reflection.rb +57 -1
- data/lib/active_model/serializer/type.rb +1 -1
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model_serializers.rb +17 -0
- data/lib/active_model_serializers/adapter.rb +92 -0
- data/lib/active_model_serializers/adapter/attributes.rb +94 -0
- data/lib/active_model_serializers/adapter/base.rb +90 -0
- data/lib/active_model_serializers/adapter/json.rb +11 -0
- data/lib/active_model_serializers/adapter/json_api.rb +513 -0
- data/lib/active_model_serializers/adapter/json_api/deserialization.rb +213 -0
- data/lib/active_model_serializers/adapter/json_api/error.rb +96 -0
- data/lib/active_model_serializers/adapter/json_api/jsonapi.rb +49 -0
- data/lib/active_model_serializers/adapter/json_api/link.rb +83 -0
- data/lib/active_model_serializers/adapter/json_api/meta.rb +37 -0
- data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +57 -0
- data/lib/active_model_serializers/adapter/json_api/relationship.rb +52 -0
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +37 -0
- data/lib/active_model_serializers/adapter/null.rb +10 -0
- data/lib/active_model_serializers/cached_serializer.rb +87 -0
- data/lib/active_model_serializers/callbacks.rb +1 -1
- data/lib/active_model_serializers/deprecate.rb +55 -0
- data/lib/active_model_serializers/deserialization.rb +2 -2
- data/lib/active_model_serializers/fragment_cache.rb +118 -0
- data/lib/active_model_serializers/json_pointer.rb +14 -0
- data/lib/active_model_serializers/key_transform.rb +70 -0
- data/lib/active_model_serializers/logging.rb +4 -1
- data/lib/active_model_serializers/model.rb +11 -1
- data/lib/active_model_serializers/railtie.rb +9 -1
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +64 -0
- data/lib/active_model_serializers/serializable_resource.rb +81 -0
- data/lib/active_model_serializers/serialization_context.rb +24 -2
- data/lib/active_model_serializers/test/schema.rb +2 -2
- data/lib/grape/formatters/active_model_serializers.rb +1 -1
- data/test/action_controller/adapter_selector_test.rb +1 -1
- data/test/action_controller/json_api/deserialization_test.rb +56 -3
- data/test/action_controller/json_api/errors_test.rb +41 -0
- data/test/action_controller/json_api/linked_test.rb +10 -9
- data/test/action_controller/json_api/pagination_test.rb +2 -2
- data/test/action_controller/json_api/transform_test.rb +180 -0
- data/test/action_controller/serialization_scope_name_test.rb +201 -35
- data/test/action_controller/serialization_test.rb +39 -7
- data/test/active_model_serializers/adapter_for_test.rb +208 -0
- data/test/active_model_serializers/cached_serializer_test.rb +80 -0
- data/test/active_model_serializers/fragment_cache_test.rb +34 -0
- data/test/active_model_serializers/json_pointer_test.rb +20 -0
- data/test/active_model_serializers/key_transform_test.rb +263 -0
- data/test/active_model_serializers/logging_test.rb +8 -8
- data/test/active_model_serializers/railtie_test_isolated.rb +6 -0
- data/test/active_model_serializers/serialization_context_test_isolated.rb +58 -0
- data/test/adapter/deprecation_test.rb +100 -0
- data/test/adapter/json/belongs_to_test.rb +32 -34
- data/test/adapter/json/collection_test.rb +73 -75
- data/test/adapter/json/has_many_test.rb +36 -38
- data/test/adapter/json/transform_test.rb +93 -0
- data/test/adapter/json_api/belongs_to_test.rb +127 -129
- data/test/adapter/json_api/collection_test.rb +80 -82
- data/test/adapter/json_api/errors_test.rb +78 -0
- data/test/adapter/json_api/fields_test.rb +68 -70
- data/test/adapter/json_api/has_many_embed_ids_test.rb +32 -34
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +75 -77
- data/test/adapter/json_api/has_many_test.rb +121 -123
- data/test/adapter/json_api/has_one_test.rb +59 -61
- data/test/adapter/json_api/json_api_test.rb +28 -30
- data/test/adapter/json_api/linked_test.rb +319 -321
- data/test/adapter/json_api/links_test.rb +75 -50
- data/test/adapter/json_api/pagination_links_test.rb +115 -82
- data/test/adapter/json_api/parse_test.rb +114 -116
- data/test/adapter/json_api/relationship_test.rb +161 -0
- data/test/adapter/json_api/relationships_test.rb +199 -0
- data/test/adapter/json_api/resource_identifier_test.rb +85 -0
- data/test/adapter/json_api/resource_meta_test.rb +100 -0
- data/test/adapter/json_api/toplevel_jsonapi_test.rb +61 -63
- data/test/adapter/json_api/transform_test.rb +500 -0
- data/test/adapter/json_api/type_test.rb +61 -0
- data/test/adapter/json_test.rb +35 -37
- data/test/adapter/null_test.rb +13 -15
- data/test/adapter/polymorphic_test.rb +72 -0
- data/test/adapter_test.rb +27 -29
- data/test/array_serializer_test.rb +7 -8
- data/test/benchmark/app.rb +65 -0
- data/test/benchmark/benchmarking_support.rb +67 -0
- data/test/benchmark/bm_caching.rb +117 -0
- data/test/benchmark/bm_transform.rb +34 -0
- data/test/benchmark/config.ru +3 -0
- data/test/benchmark/controllers.rb +77 -0
- data/test/benchmark/fixtures.rb +167 -0
- data/test/cache_test.rb +388 -0
- data/test/collection_serializer_test.rb +10 -0
- data/test/fixtures/active_record.rb +12 -0
- data/test/fixtures/poro.rb +28 -3
- data/test/grape_test.rb +5 -5
- data/test/lint_test.rb +9 -0
- data/test/serializable_resource_test.rb +59 -3
- data/test/serializers/associations_test.rb +8 -8
- data/test/serializers/attribute_test.rb +7 -7
- data/test/serializers/caching_configuration_test_isolated.rb +170 -0
- data/test/serializers/meta_test.rb +74 -6
- data/test/serializers/read_attribute_for_serialization_test.rb +79 -0
- data/test/serializers/serialization_test.rb +55 -0
- data/test/support/isolated_unit.rb +3 -0
- data/test/support/rails5_shims.rb +26 -8
- data/test/support/rails_app.rb +38 -18
- data/test/support/serialization_testing.rb +5 -5
- data/test/test_helper.rb +6 -10
- metadata +132 -37
- data/docs/DESIGN.textile +7 -1
- data/lib/active_model/serializer/adapter/cached_serializer.rb +0 -45
- data/lib/active_model/serializer/adapter/fragment_cache.rb +0 -111
- data/lib/active_model/serializer/adapter/json/fragment_cache.rb +0 -13
- data/lib/active_model/serializer/adapter/json_api/deserialization.rb +0 -207
- data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +0 -21
- data/lib/active_model/serializer/adapter/json_api/link.rb +0 -44
- data/lib/active_model/serializer/adapter/json_api/pagination_links.rb +0 -58
- data/test/active_model_serializers/serialization_context_test.rb +0 -18
- data/test/adapter/fragment_cache_test.rb +0 -38
- data/test/adapter/json_api/resource_type_config_test.rb +0 -71
- data/test/serializers/adapter_for_test.rb +0 -166
- data/test/serializers/cache_test.rb +0 -209
- data/test/support/simplecov.rb +0 -6
- data/test/support/stream_capture.rb +0 -50
- data/test/support/test_case.rb +0 -19
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.0.rc5
|
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-
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -115,33 +115,33 @@ dependencies:
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '1.6'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: simplecov
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '0.
|
123
|
+
version: '0.11'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '0.
|
130
|
+
version: '0.11'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
132
|
+
name: timecop
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- - "
|
135
|
+
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '0'
|
137
|
+
version: '0.7'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
|
-
- - "
|
142
|
+
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '0'
|
144
|
+
version: '0.7'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: grape
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +176,26 @@ dependencies:
|
|
176
176
|
- - ">="
|
177
177
|
- !ruby/object:Gem::Version
|
178
178
|
version: '0'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: rake
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '10.0'
|
186
|
+
- - "<"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '12.0'
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '10.0'
|
196
|
+
- - "<"
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '12.0'
|
179
199
|
description: ActiveModel::Serializers allows you to generate your JSON in an object-oriented
|
180
200
|
and convention-driven manner.
|
181
201
|
email:
|
@@ -184,6 +204,8 @@ executables: []
|
|
184
204
|
extensions: []
|
185
205
|
extra_rdoc_files: []
|
186
206
|
files:
|
207
|
+
- ".github/ISSUE_TEMPLATE.md"
|
208
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
187
209
|
- ".gitignore"
|
188
210
|
- ".rubocop.yml"
|
189
211
|
- ".rubocop_todo.yml"
|
@@ -192,19 +214,24 @@ files:
|
|
192
214
|
- CHANGELOG.md
|
193
215
|
- CONTRIBUTING.md
|
194
216
|
- Gemfile
|
195
|
-
- LICENSE
|
217
|
+
- MIT-LICENSE
|
196
218
|
- README.md
|
197
219
|
- Rakefile
|
198
220
|
- active_model_serializers.gemspec
|
199
221
|
- appveyor.yml
|
222
|
+
- bin/bench
|
223
|
+
- bin/bench_regression
|
224
|
+
- bin/serve_benchmark
|
200
225
|
- docs/ARCHITECTURE.md
|
201
|
-
- docs/DESIGN.textile
|
202
226
|
- docs/README.md
|
227
|
+
- docs/STYLE.md
|
203
228
|
- docs/general/adapters.md
|
204
229
|
- docs/general/caching.md
|
205
230
|
- docs/general/configuration_options.md
|
231
|
+
- docs/general/deserialization.md
|
206
232
|
- docs/general/getting_started.md
|
207
233
|
- docs/general/instrumentation.md
|
234
|
+
- docs/general/key_transforms.md
|
208
235
|
- docs/general/logging.md
|
209
236
|
- docs/general/rendering.md
|
210
237
|
- docs/general/serializers.md
|
@@ -212,26 +239,23 @@ files:
|
|
212
239
|
- docs/howto/add_pagination_links.md
|
213
240
|
- docs/howto/add_root_key.md
|
214
241
|
- docs/howto/outside_controller_use.md
|
242
|
+
- docs/howto/passing_arbitrary_options.md
|
215
243
|
- docs/howto/test.md
|
216
244
|
- docs/integrations/ember-and-json-api.md
|
217
245
|
- docs/integrations/grape.md
|
246
|
+
- docs/jsonapi/errors.md
|
218
247
|
- docs/jsonapi/schema.md
|
219
248
|
- docs/jsonapi/schema/schema.json
|
249
|
+
- docs/rfcs/0000-namespace.md
|
250
|
+
- docs/rfcs/template.md
|
220
251
|
- lib/action_controller/serialization.rb
|
221
252
|
- lib/active_model/serializable_resource.rb
|
222
253
|
- lib/active_model/serializer.rb
|
223
254
|
- lib/active_model/serializer/adapter.rb
|
224
255
|
- lib/active_model/serializer/adapter/attributes.rb
|
225
256
|
- lib/active_model/serializer/adapter/base.rb
|
226
|
-
- lib/active_model/serializer/adapter/cached_serializer.rb
|
227
|
-
- lib/active_model/serializer/adapter/fragment_cache.rb
|
228
257
|
- lib/active_model/serializer/adapter/json.rb
|
229
|
-
- lib/active_model/serializer/adapter/json/fragment_cache.rb
|
230
258
|
- lib/active_model/serializer/adapter/json_api.rb
|
231
|
-
- lib/active_model/serializer/adapter/json_api/deserialization.rb
|
232
|
-
- lib/active_model/serializer/adapter/json_api/fragment_cache.rb
|
233
|
-
- lib/active_model/serializer/adapter/json_api/link.rb
|
234
|
-
- lib/active_model/serializer/adapter/json_api/pagination_links.rb
|
235
259
|
- lib/active_model/serializer/adapter/null.rb
|
236
260
|
- lib/active_model/serializer/array_serializer.rb
|
237
261
|
- lib/active_model/serializer/association.rb
|
@@ -243,6 +267,8 @@ files:
|
|
243
267
|
- lib/active_model/serializer/collection_reflection.rb
|
244
268
|
- lib/active_model/serializer/collection_serializer.rb
|
245
269
|
- lib/active_model/serializer/configuration.rb
|
270
|
+
- lib/active_model/serializer/error_serializer.rb
|
271
|
+
- lib/active_model/serializer/errors_serializer.rb
|
246
272
|
- lib/active_model/serializer/field.rb
|
247
273
|
- lib/active_model/serializer/fieldset.rb
|
248
274
|
- lib/active_model/serializer/has_many_reflection.rb
|
@@ -250,16 +276,39 @@ files:
|
|
250
276
|
- lib/active_model/serializer/include_tree.rb
|
251
277
|
- lib/active_model/serializer/links.rb
|
252
278
|
- lib/active_model/serializer/lint.rb
|
279
|
+
- lib/active_model/serializer/meta.rb
|
280
|
+
- lib/active_model/serializer/null.rb
|
253
281
|
- lib/active_model/serializer/reflection.rb
|
254
282
|
- lib/active_model/serializer/singular_reflection.rb
|
255
283
|
- lib/active_model/serializer/type.rb
|
256
284
|
- lib/active_model/serializer/version.rb
|
257
285
|
- lib/active_model_serializers.rb
|
286
|
+
- lib/active_model_serializers/adapter.rb
|
287
|
+
- lib/active_model_serializers/adapter/attributes.rb
|
288
|
+
- lib/active_model_serializers/adapter/base.rb
|
289
|
+
- lib/active_model_serializers/adapter/json.rb
|
290
|
+
- lib/active_model_serializers/adapter/json_api.rb
|
291
|
+
- lib/active_model_serializers/adapter/json_api/deserialization.rb
|
292
|
+
- lib/active_model_serializers/adapter/json_api/error.rb
|
293
|
+
- lib/active_model_serializers/adapter/json_api/jsonapi.rb
|
294
|
+
- lib/active_model_serializers/adapter/json_api/link.rb
|
295
|
+
- lib/active_model_serializers/adapter/json_api/meta.rb
|
296
|
+
- lib/active_model_serializers/adapter/json_api/pagination_links.rb
|
297
|
+
- lib/active_model_serializers/adapter/json_api/relationship.rb
|
298
|
+
- lib/active_model_serializers/adapter/json_api/resource_identifier.rb
|
299
|
+
- lib/active_model_serializers/adapter/null.rb
|
300
|
+
- lib/active_model_serializers/cached_serializer.rb
|
258
301
|
- lib/active_model_serializers/callbacks.rb
|
302
|
+
- lib/active_model_serializers/deprecate.rb
|
259
303
|
- lib/active_model_serializers/deserialization.rb
|
304
|
+
- lib/active_model_serializers/fragment_cache.rb
|
305
|
+
- lib/active_model_serializers/json_pointer.rb
|
306
|
+
- lib/active_model_serializers/key_transform.rb
|
260
307
|
- lib/active_model_serializers/logging.rb
|
261
308
|
- lib/active_model_serializers/model.rb
|
262
309
|
- lib/active_model_serializers/railtie.rb
|
310
|
+
- lib/active_model_serializers/register_jsonapi_renderer.rb
|
311
|
+
- lib/active_model_serializers/serializable_resource.rb
|
263
312
|
- lib/active_model_serializers/serialization_context.rb
|
264
313
|
- lib/active_model_serializers/test.rb
|
265
314
|
- lib/active_model_serializers/test/schema.rb
|
@@ -275,23 +324,32 @@ files:
|
|
275
324
|
- test/action_controller/explicit_serializer_test.rb
|
276
325
|
- test/action_controller/json/include_test.rb
|
277
326
|
- test/action_controller/json_api/deserialization_test.rb
|
327
|
+
- test/action_controller/json_api/errors_test.rb
|
278
328
|
- test/action_controller/json_api/linked_test.rb
|
279
329
|
- test/action_controller/json_api/pagination_test.rb
|
330
|
+
- test/action_controller/json_api/transform_test.rb
|
280
331
|
- test/action_controller/serialization_scope_name_test.rb
|
281
332
|
- test/action_controller/serialization_test.rb
|
333
|
+
- test/active_model_serializers/adapter_for_test.rb
|
334
|
+
- test/active_model_serializers/cached_serializer_test.rb
|
335
|
+
- test/active_model_serializers/fragment_cache_test.rb
|
336
|
+
- test/active_model_serializers/json_pointer_test.rb
|
337
|
+
- test/active_model_serializers/key_transform_test.rb
|
282
338
|
- test/active_model_serializers/logging_test.rb
|
283
339
|
- test/active_model_serializers/model_test.rb
|
284
340
|
- test/active_model_serializers/railtie_test_isolated.rb
|
285
|
-
- test/active_model_serializers/
|
341
|
+
- test/active_model_serializers/serialization_context_test_isolated.rb
|
286
342
|
- test/active_model_serializers/test/schema_test.rb
|
287
343
|
- test/active_model_serializers/test/serializer_test.rb
|
288
344
|
- test/active_record_test.rb
|
289
|
-
- test/adapter/
|
345
|
+
- test/adapter/deprecation_test.rb
|
290
346
|
- test/adapter/json/belongs_to_test.rb
|
291
347
|
- test/adapter/json/collection_test.rb
|
292
348
|
- test/adapter/json/has_many_test.rb
|
349
|
+
- test/adapter/json/transform_test.rb
|
293
350
|
- test/adapter/json_api/belongs_to_test.rb
|
294
351
|
- test/adapter/json_api/collection_test.rb
|
352
|
+
- test/adapter/json_api/errors_test.rb
|
295
353
|
- test/adapter/json_api/fields_test.rb
|
296
354
|
- test/adapter/json_api/has_many_embed_ids_test.rb
|
297
355
|
- test/adapter/json_api/has_many_explicit_serializer_test.rb
|
@@ -302,12 +360,26 @@ files:
|
|
302
360
|
- test/adapter/json_api/links_test.rb
|
303
361
|
- test/adapter/json_api/pagination_links_test.rb
|
304
362
|
- test/adapter/json_api/parse_test.rb
|
305
|
-
- test/adapter/json_api/
|
363
|
+
- test/adapter/json_api/relationship_test.rb
|
364
|
+
- test/adapter/json_api/relationships_test.rb
|
365
|
+
- test/adapter/json_api/resource_identifier_test.rb
|
366
|
+
- test/adapter/json_api/resource_meta_test.rb
|
306
367
|
- test/adapter/json_api/toplevel_jsonapi_test.rb
|
368
|
+
- test/adapter/json_api/transform_test.rb
|
369
|
+
- test/adapter/json_api/type_test.rb
|
307
370
|
- test/adapter/json_test.rb
|
308
371
|
- test/adapter/null_test.rb
|
372
|
+
- test/adapter/polymorphic_test.rb
|
309
373
|
- test/adapter_test.rb
|
310
374
|
- test/array_serializer_test.rb
|
375
|
+
- test/benchmark/app.rb
|
376
|
+
- test/benchmark/benchmarking_support.rb
|
377
|
+
- test/benchmark/bm_caching.rb
|
378
|
+
- test/benchmark/bm_transform.rb
|
379
|
+
- test/benchmark/config.ru
|
380
|
+
- test/benchmark/controllers.rb
|
381
|
+
- test/benchmark/fixtures.rb
|
382
|
+
- test/cache_test.rb
|
311
383
|
- test/collection_serializer_test.rb
|
312
384
|
- test/fixtures/active_record.rb
|
313
385
|
- test/fixtures/poro.rb
|
@@ -321,17 +393,18 @@ files:
|
|
321
393
|
- test/logger_test.rb
|
322
394
|
- test/poro_test.rb
|
323
395
|
- test/serializable_resource_test.rb
|
324
|
-
- test/serializers/adapter_for_test.rb
|
325
396
|
- test/serializers/association_macros_test.rb
|
326
397
|
- test/serializers/associations_test.rb
|
327
398
|
- test/serializers/attribute_test.rb
|
328
399
|
- test/serializers/attributes_test.rb
|
329
|
-
- test/serializers/
|
400
|
+
- test/serializers/caching_configuration_test_isolated.rb
|
330
401
|
- test/serializers/configuration_test.rb
|
331
402
|
- test/serializers/fieldset_test.rb
|
332
403
|
- test/serializers/meta_test.rb
|
333
404
|
- test/serializers/options_test.rb
|
405
|
+
- test/serializers/read_attribute_for_serialization_test.rb
|
334
406
|
- test/serializers/root_test.rb
|
407
|
+
- test/serializers/serialization_test.rb
|
335
408
|
- test/serializers/serializer_for_test.rb
|
336
409
|
- test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json
|
337
410
|
- test/support/isolated_unit.rb
|
@@ -344,15 +417,15 @@ files:
|
|
344
417
|
- test/support/schemas/render_using_json_api.json
|
345
418
|
- test/support/schemas/simple_json_pointers.json
|
346
419
|
- test/support/serialization_testing.rb
|
347
|
-
- test/support/simplecov.rb
|
348
|
-
- test/support/stream_capture.rb
|
349
|
-
- test/support/test_case.rb
|
350
420
|
- test/test_helper.rb
|
351
421
|
homepage: https://github.com/rails-api/active_model_serializers
|
352
422
|
licenses:
|
353
423
|
- MIT
|
354
424
|
metadata: {}
|
355
|
-
post_install_message:
|
425
|
+
post_install_message: |
|
426
|
+
NOTE: The default key case for the JsonApi adapter has changed to dashed.
|
427
|
+
See https://github.com/rails-api/active_model_serializers/blob/master/docs/general/key_transform.md
|
428
|
+
for more information on configuring this behavior.
|
356
429
|
rdoc_options: []
|
357
430
|
require_paths:
|
358
431
|
- lib
|
@@ -368,7 +441,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
368
441
|
version: 1.3.1
|
369
442
|
requirements: []
|
370
443
|
rubyforge_project:
|
371
|
-
rubygems_version: 2.
|
444
|
+
rubygems_version: 2.4.8
|
372
445
|
signing_key:
|
373
446
|
specification_version: 4
|
374
447
|
summary: Conventions-based JSON generation for Rails.
|
@@ -377,23 +450,32 @@ test_files:
|
|
377
450
|
- test/action_controller/explicit_serializer_test.rb
|
378
451
|
- test/action_controller/json/include_test.rb
|
379
452
|
- test/action_controller/json_api/deserialization_test.rb
|
453
|
+
- test/action_controller/json_api/errors_test.rb
|
380
454
|
- test/action_controller/json_api/linked_test.rb
|
381
455
|
- test/action_controller/json_api/pagination_test.rb
|
456
|
+
- test/action_controller/json_api/transform_test.rb
|
382
457
|
- test/action_controller/serialization_scope_name_test.rb
|
383
458
|
- test/action_controller/serialization_test.rb
|
459
|
+
- test/active_model_serializers/adapter_for_test.rb
|
460
|
+
- test/active_model_serializers/cached_serializer_test.rb
|
461
|
+
- test/active_model_serializers/fragment_cache_test.rb
|
462
|
+
- test/active_model_serializers/json_pointer_test.rb
|
463
|
+
- test/active_model_serializers/key_transform_test.rb
|
384
464
|
- test/active_model_serializers/logging_test.rb
|
385
465
|
- test/active_model_serializers/model_test.rb
|
386
466
|
- test/active_model_serializers/railtie_test_isolated.rb
|
387
|
-
- test/active_model_serializers/
|
467
|
+
- test/active_model_serializers/serialization_context_test_isolated.rb
|
388
468
|
- test/active_model_serializers/test/schema_test.rb
|
389
469
|
- test/active_model_serializers/test/serializer_test.rb
|
390
470
|
- test/active_record_test.rb
|
391
|
-
- test/adapter/
|
471
|
+
- test/adapter/deprecation_test.rb
|
392
472
|
- test/adapter/json/belongs_to_test.rb
|
393
473
|
- test/adapter/json/collection_test.rb
|
394
474
|
- test/adapter/json/has_many_test.rb
|
475
|
+
- test/adapter/json/transform_test.rb
|
395
476
|
- test/adapter/json_api/belongs_to_test.rb
|
396
477
|
- test/adapter/json_api/collection_test.rb
|
478
|
+
- test/adapter/json_api/errors_test.rb
|
397
479
|
- test/adapter/json_api/fields_test.rb
|
398
480
|
- test/adapter/json_api/has_many_embed_ids_test.rb
|
399
481
|
- test/adapter/json_api/has_many_explicit_serializer_test.rb
|
@@ -404,12 +486,26 @@ test_files:
|
|
404
486
|
- test/adapter/json_api/links_test.rb
|
405
487
|
- test/adapter/json_api/pagination_links_test.rb
|
406
488
|
- test/adapter/json_api/parse_test.rb
|
407
|
-
- test/adapter/json_api/
|
489
|
+
- test/adapter/json_api/relationship_test.rb
|
490
|
+
- test/adapter/json_api/relationships_test.rb
|
491
|
+
- test/adapter/json_api/resource_identifier_test.rb
|
492
|
+
- test/adapter/json_api/resource_meta_test.rb
|
408
493
|
- test/adapter/json_api/toplevel_jsonapi_test.rb
|
494
|
+
- test/adapter/json_api/transform_test.rb
|
495
|
+
- test/adapter/json_api/type_test.rb
|
409
496
|
- test/adapter/json_test.rb
|
410
497
|
- test/adapter/null_test.rb
|
498
|
+
- test/adapter/polymorphic_test.rb
|
411
499
|
- test/adapter_test.rb
|
412
500
|
- test/array_serializer_test.rb
|
501
|
+
- test/benchmark/app.rb
|
502
|
+
- test/benchmark/benchmarking_support.rb
|
503
|
+
- test/benchmark/bm_caching.rb
|
504
|
+
- test/benchmark/bm_transform.rb
|
505
|
+
- test/benchmark/config.ru
|
506
|
+
- test/benchmark/controllers.rb
|
507
|
+
- test/benchmark/fixtures.rb
|
508
|
+
- test/cache_test.rb
|
413
509
|
- test/collection_serializer_test.rb
|
414
510
|
- test/fixtures/active_record.rb
|
415
511
|
- test/fixtures/poro.rb
|
@@ -423,17 +519,18 @@ test_files:
|
|
423
519
|
- test/logger_test.rb
|
424
520
|
- test/poro_test.rb
|
425
521
|
- test/serializable_resource_test.rb
|
426
|
-
- test/serializers/adapter_for_test.rb
|
427
522
|
- test/serializers/association_macros_test.rb
|
428
523
|
- test/serializers/associations_test.rb
|
429
524
|
- test/serializers/attribute_test.rb
|
430
525
|
- test/serializers/attributes_test.rb
|
431
|
-
- test/serializers/
|
526
|
+
- test/serializers/caching_configuration_test_isolated.rb
|
432
527
|
- test/serializers/configuration_test.rb
|
433
528
|
- test/serializers/fieldset_test.rb
|
434
529
|
- test/serializers/meta_test.rb
|
435
530
|
- test/serializers/options_test.rb
|
531
|
+
- test/serializers/read_attribute_for_serialization_test.rb
|
436
532
|
- test/serializers/root_test.rb
|
533
|
+
- test/serializers/serialization_test.rb
|
437
534
|
- test/serializers/serializer_for_test.rb
|
438
535
|
- test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json
|
439
536
|
- test/support/isolated_unit.rb
|
@@ -446,7 +543,5 @@ test_files:
|
|
446
543
|
- test/support/schemas/render_using_json_api.json
|
447
544
|
- test/support/schemas/simple_json_pointers.json
|
448
545
|
- test/support/serialization_testing.rb
|
449
|
-
- test/support/simplecov.rb
|
450
|
-
- test/support/stream_capture.rb
|
451
|
-
- test/support/test_case.rb
|
452
546
|
- test/test_helper.rb
|
547
|
+
has_rdoc:
|
data/docs/DESIGN.textile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<strong>This was the original design document for serializers.</strong> It is useful mostly for historical purposes as the public API has changed.
|
2
|
def initialize(post, scope)
|
3
1
|
@post, @scope = post, scope
|
4
2
|
end
|
5
3
|
def as_json
|
6
4
|
{ post: { title: @post.name, body: @post.body } }
|
7
5
|
end
|
8
6
|
def show
|
9
7
|
@post = Post.find(params[:id])
|
10
8
|
render json: @post
|
11
9
|
end
|
12
10
|
def initialize(post, scope)
|
13
11
|
@post, @scope = post, scope
|
14
12
|
end
|
15
13
|
def serializable_hash
|
16
14
|
{ title: @post.name, body: @post.body }
|
17
15
|
end
|
18
16
|
def as_json
|
19
17
|
{ post: serializable_hash }
|
20
18
|
end
|
21
19
|
def initialize(post, scope)
|
22
20
|
@post, @scope = post, scope
|
23
21
|
end
|
24
22
|
def as_json
|
25
23
|
{ post: serializable_hash }
|
26
24
|
end
|
27
25
|
def serializable_hash
|
28
26
|
hash = post
|
29
27
|
hash.merge!(super_data) if super?
|
30
28
|
hash
|
31
29
|
end
|
32
30
|
def post
|
33
31
|
{ title: @post.name, body: @post.body }
|
34
32
|
end
|
35
33
|
def super_data
|
36
34
|
{ email: @post.email }
|
37
35
|
end
|
38
36
|
def super?
|
39
37
|
@scope.superuser?
|
40
38
|
end
|
41
39
|
# For now, we use a very simple authorization structure. These tests will need
|
42
40
|
# refactoring if we change that.
|
43
41
|
plebe = OpenStruct.new(super?: false)
|
44
42
|
god = OpenStruct.new(super?: true)
|
45
43
|
post = OpenStruct.new(title: "Welcome to my blog!", body: "Blah blah blah", email: "tenderlove@gmail.com")
|
46
44
|
test "a regular user sees just the title and body" do
|
47
45
|
json = PostSerializer.new(post, plebe).to_json
|
48
46
|
hash = JSON.parse(json)
|
49
47
|
assert_equal post.title, hash.delete("title")
|
50
48
|
assert_equal post.body, hash.delete("body")
|
51
49
|
assert_empty hash
|
52
50
|
end
|
53
51
|
test "a superuser sees the title, body and email" do
|
54
52
|
json = PostSerializer.new(post, god).to_json
|
55
53
|
hash = JSON.parse(json)
|
56
54
|
assert_equal post.title, hash.delete("title")
|
57
55
|
assert_equal post.body, hash.delete("body")
|
58
56
|
assert_equal post.email, hash.delete("email")
|
59
57
|
assert_empty hash
|
60
58
|
end
|
61
59
|
# @param [~body, ~title, ~email] post the post to serialize
|
62
60
|
# @param [~super] scope the authorization scope for this serializer
|
63
61
|
def initialize(post, scope)
|
64
62
|
@post, @scope = post, scope
|
65
63
|
end
|
66
64
|
# ...
|
65
|
+
ActiveModel::Serializer+ to simplify our post serializer.
|
67
66
|
attributes :title, :body
|
68
67
|
def serializable_hash
|
69
68
|
hash = attributes
|
70
69
|
hash.merge!(super_data) if super?
|
71
70
|
hash
|
72
71
|
end
|
73
72
|
def super_data
|
74
73
|
{ email: @post.email }
|
75
74
|
end
|
76
75
|
def super?
|
77
76
|
@scope.superuser?
|
78
77
|
end
|
78
|
+
attributes+ that extracts those attributes from the post model.
|
79
79
|
attributes :title, :body
|
80
80
|
def attributes
|
81
81
|
hash = super
|
82
82
|
hash.merge!(email: post.email) if super?
|
83
83
|
hash
|
84
84
|
end
|
85
85
|
def super?
|
86
86
|
@scope.superuser?
|
87
87
|
end
|
88
|
+
attributes+. We can call +super+ to get the hash based on the attributes we declared, and then add in any additional
|
88
89
|
attributes :title, :body
|
89
90
|
has_many :comments
|
90
91
|
def attributes
|
91
92
|
hash = super
|
92
93
|
hash.merge!(email: post.email) if super?
|
93
94
|
hash
|
94
95
|
end
|
95
96
|
def super?
|
96
97
|
@scope.superuser?
|
97
98
|
end
|
98
99
|
post: {
|
99
100
|
title: "Hello Blog!",
|
100
101
|
body: "This is my first post. Isn't it fabulous!",
|
101
102
|
comments: [
|
102
103
|
{
|
103
104
|
title: "Awesome",
|
104
105
|
body: "Your first post is great"
|
105
106
|
}
|
106
107
|
]
|
107
108
|
}
|
108
109
|
def initialize(comment, scope)
|
109
110
|
@comment, @scope = comment, scope
|
110
111
|
end
|
111
112
|
def serializable_hash
|
112
113
|
{ title: @comment.title }
|
113
114
|
end
|
114
115
|
def as_json
|
115
116
|
{ comment: serializable_hash }
|
116
117
|
end
|
117
118
|
post: {
|
118
119
|
title: "Hello Blog!",
|
119
120
|
body: "This is my first post. Isn't it fabulous!",
|
120
121
|
comments: [{ title: "Awesome" }]
|
121
122
|
}
|
123
|
+
comments+ accessor on the post object. We can override the +comments+ accessor to limit the comments used
|
122
124
|
attributes :title. :body
|
123
125
|
has_many :comments
|
124
126
|
def attributes
|
125
127
|
hash = super
|
126
128
|
hash.merge!(email: post.email) if super?
|
127
129
|
hash
|
128
130
|
end
|
129
131
|
def comments
|
130
132
|
post.comments_for(scope)
|
131
133
|
end
|
132
134
|
def super?
|
133
135
|
@scope.superuser?
|
134
136
|
end
|
137
|
+
ActiveModel::Serializer+ will still embed the comments, but this time it will use just the comments
|
135
138
|
has_many :followed_posts, :key => :posts
|
136
139
|
has_one :owned_account, :key => :account
|
137
140
|
has_many :followed_posts, :key => :posts, :serializer => CustomPostSerializer
|
138
141
|
has_one :owne_account, :key => :account, :serializer => PrivateAccountSerializer
|
139
142
|
post: {
|
140
143
|
id: 1
|
141
144
|
title: "Hello Blog!",
|
142
145
|
body: "This is my first post. Isn't it fabulous!",
|
143
146
|
comments: [1,2]
|
144
147
|
},
|
145
148
|
comments: [
|
146
149
|
{
|
147
150
|
id: 1
|
148
151
|
title: "Awesome",
|
149
152
|
body: "Your first post is great"
|
150
153
|
},
|
151
154
|
{
|
152
155
|
id: 2
|
153
156
|
title: "Not so awesome",
|
154
157
|
body: "Why is it so short!"
|
155
158
|
}
|
156
159
|
]
|
157
160
|
attributes :id, :title, :body
|
158
161
|
# define any logic for dealing with authorization-based attributes here
|
159
162
|
attributes :title, :body
|
160
163
|
has_many :comments
|
161
164
|
def as_json
|
162
165
|
{ post: serializable_hash }.merge!(associations)
|
163
166
|
end
|
164
167
|
def serializable_hash
|
165
168
|
post_hash = attributes
|
166
169
|
post_hash.merge!(association_ids)
|
167
170
|
post_hash
|
168
171
|
end
|
169
172
|
def attributes
|
170
173
|
hash = super
|
171
174
|
hash.merge!(email: post.email) if super?
|
172
175
|
hash
|
173
176
|
end
|
174
177
|
def comments
|
175
178
|
post.comments_for(scope)
|
176
179
|
end
|
177
180
|
def super?
|
178
181
|
@scope.superuser?
|
179
182
|
end
|
183
|
+
associations+, creates a hash of all of the define associations, using their defined
|
184
|
+
comments+ method.
|
180
185
|
class CommentSerializer < ActiveModel::Serializer
|
181
186
|
attributes :id, :title
|
182
187
|
end
|
183
188
|
# same as before
|
184
189
|
# ...
|
185
190
|
serialization_scope :current_app
|
186
191
|
posts: [
|
187
192
|
{
|
188
193
|
title: "FIRST POST!",
|
189
194
|
body: "It's my first pooooost"
|
190
195
|
},
|
191
196
|
{ title: "Second post!",
|
192
197
|
body: "Zomg I made it to my second post"
|
193
198
|
}
|
194
199
|
]
|
195
200
|
def serializable_array
|
196
201
|
serializers.map do |serializer|
|
197
202
|
serializer.serializable_hash
|
198
203
|
end
|
199
204
|
end
|
200
205
|
def as_json
|
201
206
|
hash = { root => serializable_array }
|
202
207
|
hash.merge!(associations)
|
203
208
|
hash
|
204
209
|
end
|