Extract context build to a method

This commit is contained in:
Adrian Mugnolo and Santiago Pastorino 2014-01-06 15:48:41 -02:00 committed by Santiago Pastorino
parent 0d8ef2b165
commit dc32b5fc1b

View File

@ -65,11 +65,21 @@ module ActionController
options = default_serializer_options.merge(options)
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)
serializer.new(resource, options)
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