mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Extract context build to a method
This commit is contained in:
parent
0d8ef2b165
commit
dc32b5fc1b
@ -65,11 +65,21 @@ module ActionController
|
|||||||
options = default_serializer_options.merge(options)
|
options = default_serializer_options.merge(options)
|
||||||
|
|
||||||
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
|
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
|
||||||
options[:context] = { scope: serialization_scope }.merge!(options[:context] || {})
|
options[:context] = build_context_from options[:context]
|
||||||
options[:resource_name] = controller_name if resource.respond_to?(:to_ary)
|
options[:resource_name] = controller_name if resource.respond_to?(:to_ary)
|
||||||
|
|
||||||
serializer.new(resource, options)
|
serializer.new(resource, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_context_from(context_option)
|
||||||
|
default_context.tap do |context|
|
||||||
|
context.merge! context_option if context_option
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_context
|
||||||
|
{ scope: serialization_scope }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user