@@ -43,14 +43,13 @@ def self.default_key_transform
43
43
44
44
# {http://jsonapi.org/format/#crud Requests are transactional, i.e. success or failure}
45
45
# {http://jsonapi.org/format/#document-top-level data and errors MUST NOT coexist in the same document.}
46
- def serializable_hash ( options = nil )
47
- options ||= { }
46
+ def serializable_hash ( *)
48
47
document = if serializer . success?
49
- success_document ( options )
48
+ success_document
50
49
else
51
- failure_document ( options )
50
+ failure_document
52
51
end
53
- self . class . transform_key_casing! ( document , options )
52
+ self . class . transform_key_casing! ( document , instance_options )
54
53
end
55
54
56
55
# {http://jsonapi.org/format/#document-top-level Primary data}
@@ -68,10 +67,10 @@ def serializable_hash(options = nil)
68
67
# links: toplevel_links,
69
68
# jsonapi: toplevel_jsonapi
70
69
# }.reject! {|_,v| v.nil? }
71
- def success_document ( options )
70
+ def success_document
72
71
is_collection = serializer . respond_to? ( :each )
73
72
serializers = is_collection ? serializer : [ serializer ]
74
- primary_data , included = resource_objects_for ( serializers , options )
73
+ primary_data , included = resource_objects_for ( serializers )
75
74
76
75
hash = { }
77
76
# toplevel_data
@@ -128,7 +127,7 @@ def success_document(options)
128
127
129
128
if is_collection && serializer . paginated?
130
129
hash [ :links ] ||= { }
131
- hash [ :links ] . update ( pagination_links_for ( serializer , options ) )
130
+ hash [ :links ] . update ( pagination_links_for ( serializer ) )
132
131
end
133
132
134
133
hash
@@ -148,7 +147,7 @@ def success_document(options)
148
147
# }.reject! {|_,v| v.nil? }
149
148
# prs:
150
149
# https://github.com/rails-api/active_model_serializers/pull/1004
151
- def failure_document ( options )
150
+ def failure_document
152
151
hash = { }
153
152
# PR Please :)
154
153
# Jsonapi.add!(hash)
@@ -163,10 +162,10 @@ def failure_document(options)
163
162
# ]
164
163
if serializer . respond_to? ( :each )
165
164
hash [ :errors ] = serializer . flat_map do |error_serializer |
166
- Error . resource_errors ( error_serializer , options )
165
+ Error . resource_errors ( error_serializer , instance_options )
167
166
end
168
167
else
169
- hash [ :errors ] = Error . resource_errors ( serializer , options )
168
+ hash [ :errors ] = Error . resource_errors ( serializer , instance_options )
170
169
end
171
170
hash
172
171
end
@@ -224,21 +223,21 @@ def fragment_cache(cached_hash, non_cached_hash)
224
223
# [x] url helpers https://github.com/rails-api/active_model_serializers/issues/1269
225
224
# meta
226
225
# [x] https://github.com/rails-api/active_model_serializers/pull/1340
227
- def resource_objects_for ( serializers , options )
226
+ def resource_objects_for ( serializers )
228
227
@primary = [ ]
229
228
@included = [ ]
230
229
@resource_identifiers = Set . new
231
- serializers . each { |serializer | process_resource ( serializer , true , options ) }
232
- serializers . each { |serializer | process_relationships ( serializer , @include_tree , options ) }
230
+ serializers . each { |serializer | process_resource ( serializer , true ) }
231
+ serializers . each { |serializer | process_relationships ( serializer , @include_tree ) }
233
232
234
233
[ @primary , @included ]
235
234
end
236
235
237
- def process_resource ( serializer , primary , options )
238
- resource_identifier = ResourceIdentifier . new ( serializer , options ) . as_json
236
+ def process_resource ( serializer , primary )
237
+ resource_identifier = ResourceIdentifier . new ( serializer , instance_options ) . as_json
239
238
return false unless @resource_identifiers . add? ( resource_identifier )
240
239
241
- resource_object = resource_object_for ( serializer , options )
240
+ resource_object = resource_object_for ( serializer )
242
241
if primary
243
242
@primary << resource_object
244
243
else
@@ -248,21 +247,21 @@ def process_resource(serializer, primary, options)
248
247
true
249
248
end
250
249
251
- def process_relationships ( serializer , include_tree , options )
250
+ def process_relationships ( serializer , include_tree )
252
251
serializer . associations ( include_tree ) . each do |association |
253
- process_relationship ( association . serializer , include_tree [ association . key ] , options )
252
+ process_relationship ( association . serializer , include_tree [ association . key ] )
254
253
end
255
254
end
256
255
257
- def process_relationship ( serializer , include_tree , options )
256
+ def process_relationship ( serializer , include_tree )
258
257
if serializer . respond_to? ( :each )
259
- serializer . each { |s | process_relationship ( s , include_tree , options ) }
258
+ serializer . each { |s | process_relationship ( s , include_tree ) }
260
259
return
261
260
end
262
261
return unless serializer && serializer . object
263
- return unless process_resource ( serializer , false , options )
262
+ return unless process_resource ( serializer , false )
264
263
265
- process_relationships ( serializer , include_tree , options )
264
+ process_relationships ( serializer , include_tree )
266
265
end
267
266
268
267
# {http://jsonapi.org/format/#document-resource-object-attributes Document Resource Object Attributes}
@@ -286,9 +285,9 @@ def attributes_for(serializer, fields)
286
285
end
287
286
288
287
# {http://jsonapi.org/format/#document-resource-objects Document Resource Objects}
289
- def resource_object_for ( serializer , options )
288
+ def resource_object_for ( serializer )
290
289
resource_object = cache_check ( serializer ) do
291
- resource_object = ResourceIdentifier . new ( serializer , options ) . as_json
290
+ resource_object = ResourceIdentifier . new ( serializer , instance_options ) . as_json
292
291
293
292
requested_fields = fieldset && fieldset . fields_for ( resource_object [ :type ] )
294
293
attributes = attributes_for ( serializer , requested_fields )
@@ -297,7 +296,7 @@ def resource_object_for(serializer, options)
297
296
end
298
297
299
298
requested_associations = fieldset . fields_for ( resource_object [ :type ] ) || '*'
300
- relationships = relationships_for ( serializer , requested_associations , options )
299
+ relationships = relationships_for ( serializer , requested_associations )
301
300
resource_object [ :relationships ] = relationships if relationships . any?
302
301
303
302
links = links_for ( serializer )
@@ -425,13 +424,13 @@ def resource_object_for(serializer, options)
425
424
# id: 'required-id',
426
425
# meta: meta
427
426
# }.reject! {|_,v| v.nil? }
428
- def relationships_for ( serializer , requested_associations , options )
427
+ def relationships_for ( serializer , requested_associations )
429
428
include_tree = ActiveModel ::Serializer ::IncludeTree . from_include_args ( requested_associations )
430
429
serializer . associations ( include_tree ) . each_with_object ( { } ) do |association , hash |
431
430
hash [ association . key ] = Relationship . new (
432
431
serializer ,
433
432
association . serializer ,
434
- options ,
433
+ instance_options ,
435
434
options : association . options ,
436
435
links : association . links ,
437
436
meta : association . meta
@@ -499,8 +498,8 @@ def links_for(serializer)
499
498
# end
500
499
# prs:
501
500
# https://github.com/rails-api/active_model_serializers/pull/1041
502
- def pagination_links_for ( serializer , options )
503
- PaginationLinks . new ( serializer . object , options [ :serialization_context ] ) . serializable_hash ( options )
501
+ def pagination_links_for ( serializer )
502
+ PaginationLinks . new ( serializer . object , instance_options ) . as_json
504
503
end
505
504
506
505
# {http://jsonapi.org/format/#document-meta Docment Meta}
0 commit comments