@@ -37,8 +37,8 @@ def initialize(serializer, options = {})
3737 @fieldset = options [ :fieldset ] || ActiveModel ::Serializer ::Fieldset . new ( options . delete ( :fields ) )
3838 end
3939
40- def default_key_transform
41- :dashed
40+ def self . default_key_transform
41+ :dash
4242 end
4343
4444 # {http://jsonapi.org/format/#crud Requests are transactional, i.e. success or failure}
@@ -48,9 +48,9 @@ def serializable_hash(options = nil)
4848 document = if serializer . success?
4949 success_document ( options )
5050 else
51- failure_document
51+ failure_document ( options )
5252 end
53- transform_key_casing! ( document , options [ :serialization_context ] )
53+ self . class . transform_key_casing! ( document , options )
5454 end
5555
5656 # {http://jsonapi.org/format/#document-top-level Primary data}
@@ -71,7 +71,7 @@ def serializable_hash(options = nil)
7171 def success_document ( options )
7272 is_collection = serializer . respond_to? ( :each )
7373 serializers = is_collection ? serializer : [ serializer ]
74- primary_data , included = resource_objects_for ( serializers )
74+ primary_data , included = resource_objects_for ( serializers , options )
7575
7676 hash = { }
7777 # toplevel_data
@@ -148,7 +148,7 @@ def success_document(options)
148148 # }.reject! {|_,v| v.nil? }
149149 # prs:
150150 # https://github.com/rails-api/active_model_serializers/pull/1004
151- def failure_document
151+ def failure_document ( options )
152152 hash = { }
153153 # PR Please :)
154154 # Jsonapi.add!(hash)
@@ -163,10 +163,10 @@ def failure_document
163163 # ]
164164 if serializer . respond_to? ( :each )
165165 hash [ :errors ] = serializer . flat_map do |error_serializer |
166- Error . resource_errors ( error_serializer )
166+ Error . resource_errors ( error_serializer , options )
167167 end
168168 else
169- hash [ :errors ] = Error . resource_errors ( serializer )
169+ hash [ :errors ] = Error . resource_errors ( serializer , options )
170170 end
171171 hash
172172 end
@@ -224,21 +224,21 @@ def fragment_cache(cached_hash, non_cached_hash)
224224 # [x] url helpers https://github.com/rails-api/active_model_serializers/issues/1269
225225 # meta
226226 # [x] https://github.com/rails-api/active_model_serializers/pull/1340
227- def resource_objects_for ( serializers )
227+ def resource_objects_for ( serializers , options )
228228 @primary = [ ]
229229 @included = [ ]
230230 @resource_identifiers = Set . new
231- serializers . each { |serializer | process_resource ( serializer , true ) }
232- serializers . each { |serializer | process_relationships ( serializer , @include_tree ) }
231+ serializers . each { |serializer | process_resource ( serializer , true , options ) }
232+ serializers . each { |serializer | process_relationships ( serializer , @include_tree , options ) }
233233
234234 [ @primary , @included ]
235235 end
236236
237- def process_resource ( serializer , primary )
238- resource_identifier = ResourceIdentifier . new ( serializer ) . as_json
237+ def process_resource ( serializer , primary , options )
238+ resource_identifier = ResourceIdentifier . new ( serializer , options ) . as_json
239239 return false unless @resource_identifiers . add? ( resource_identifier )
240240
241- resource_object = resource_object_for ( serializer )
241+ resource_object = resource_object_for ( serializer , options )
242242 if primary
243243 @primary << resource_object
244244 else
@@ -248,21 +248,21 @@ def process_resource(serializer, primary)
248248 true
249249 end
250250
251- def process_relationships ( serializer , include_tree )
251+ def process_relationships ( serializer , include_tree , options )
252252 serializer . associations ( include_tree ) . each do |association |
253- process_relationship ( association . serializer , include_tree [ association . key ] )
253+ process_relationship ( association . serializer , include_tree [ association . key ] , options )
254254 end
255255 end
256256
257- def process_relationship ( serializer , include_tree )
257+ def process_relationship ( serializer , include_tree , options )
258258 if serializer . respond_to? ( :each )
259- serializer . each { |s | process_relationship ( s , include_tree ) }
259+ serializer . each { |s | process_relationship ( s , include_tree , options ) }
260260 return
261261 end
262262 return unless serializer && serializer . object
263- return unless process_resource ( serializer , false )
263+ return unless process_resource ( serializer , false , options )
264264
265- process_relationships ( serializer , include_tree )
265+ process_relationships ( serializer , include_tree , options )
266266 end
267267
268268 # {http://jsonapi.org/format/#document-resource-object-attributes Document Resource Object Attributes}
@@ -286,9 +286,9 @@ def attributes_for(serializer, fields)
286286 end
287287
288288 # {http://jsonapi.org/format/#document-resource-objects Document Resource Objects}
289- def resource_object_for ( serializer )
289+ def resource_object_for ( serializer , options )
290290 resource_object = cache_check ( serializer ) do
291- resource_object = ResourceIdentifier . new ( serializer ) . as_json
291+ resource_object = ResourceIdentifier . new ( serializer , options ) . as_json
292292
293293 requested_fields = fieldset && fieldset . fields_for ( resource_object [ :type ] )
294294 attributes = attributes_for ( serializer , requested_fields )
@@ -297,7 +297,7 @@ def resource_object_for(serializer)
297297 end
298298
299299 requested_associations = fieldset . fields_for ( resource_object [ :type ] ) || '*'
300- relationships = relationships_for ( serializer , requested_associations )
300+ relationships = relationships_for ( serializer , requested_associations , options )
301301 resource_object [ :relationships ] = relationships if relationships . any?
302302
303303 links = links_for ( serializer )
@@ -425,15 +425,16 @@ def resource_object_for(serializer)
425425 # id: 'required-id',
426426 # meta: meta
427427 # }.reject! {|_,v| v.nil? }
428- def relationships_for ( serializer , requested_associations )
428+ def relationships_for ( serializer , requested_associations , options )
429429 include_tree = ActiveModel ::Serializer ::IncludeTree . from_include_args ( requested_associations )
430430 serializer . associations ( include_tree ) . each_with_object ( { } ) do |association , hash |
431431 hash [ association . key ] = Relationship . new (
432432 serializer ,
433433 association . serializer ,
434- association . options ,
435- association . links ,
436- association . meta
434+ options ,
435+ options : association . options ,
436+ links : association . links ,
437+ meta : association . meta
437438 ) . as_json
438439 end
439440 end
0 commit comments