Allow default namespace inheritance

This commit is contained in:
Gauthier Delacroix 2014-09-03 12:41:30 +02:00
parent 605408005f
commit 8514528db7
3 changed files with 6 additions and 4 deletions

View File

@ -85,8 +85,8 @@ module ActionController
options[:scope] = serialization_scope unless options.has_key?(:scope) options[:scope] = serialization_scope unless options.has_key?(:scope)
if resource.respond_to?(:to_ary) if resource.respond_to?(:to_ary)
options[:resource_name] = controller_name options[:resource_name] ||= controller_name
options[:namespace] = namespace_for_serializer if namespace_for_serializer options[:namespace] ||= namespace_for_serializer if namespace_for_serializer
end end
serializer.new(resource, options) serializer.new(resource, options)

View File

@ -35,7 +35,7 @@ module ActiveModel
def serializer_for(item) def serializer_for(item)
serializer_class = @each_serializer || Serializer.serializer_for(item, namespace: @namespace) || DefaultSerializer serializer_class = @each_serializer || Serializer.serializer_for(item, namespace: @namespace) || DefaultSerializer
serializer_class.new(item, scope: scope, key_format: key_format, only: @only, except: @except, polymorphic: @polymorphic) serializer_class.new(item, scope: scope, key_format: key_format, only: @only, except: @except, polymorphic: @polymorphic, namespace: @namespace)
end end
def serializable_object def serializable_object

View File

@ -132,6 +132,7 @@ end
@except = options[:except] ? Array(options[:except]) : nil @except = options[:except] ? Array(options[:except]) : nil
@key_format = options[:key_format] @key_format = options[:key_format]
@context = options[:context] @context = options[:context]
@namespace = options[:namespace]
end end
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context, :polymorphic attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context, :polymorphic
@ -217,7 +218,8 @@ end
end end
def association_options_for_serializer(association) def association_options_for_serializer(association)
prefix = association.options[:prefix] prefix = association.options[:prefix]
namespace = association.options[:namespace] || @namespace || self.namespace
{ scope: scope }.tap do |opts| { scope: scope }.tap do |opts|
opts[:namespace] = namespace if namespace opts[:namespace] = namespace if namespace