mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
- If a controller is in a namespace, serializer will be looked up in this namespace first.
- Serializers for associations will be looked up in a parent serializer's namespace first too. - "Prefix" option for different versions of associations serializers. Example: has_many :users, as: :short -> ShortUserSerializer TODO: tests, config option for enabling namespace lookup
This commit is contained in:
@@ -21,6 +21,7 @@ module ActiveModel
|
||||
@resource_name = options[:resource_name]
|
||||
@only = options[:only] ? Array(options[:only]) : nil
|
||||
@except = options[:except] ? Array(options[:except]) : nil
|
||||
@namespace = options[:namespace]
|
||||
@key_format = options[:key_format] || options[:each_serializer].try(:key_format)
|
||||
end
|
||||
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format
|
||||
@@ -32,7 +33,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def serializer_for(item)
|
||||
serializer_class = @each_serializer || Serializer.serializer_for(item) || 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)
|
||||
end
|
||||
|
||||
@@ -58,6 +59,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def instrumentation_keys
|
||||
[:object, :scope, :root, :meta_key, :meta, :each_serializer, :resource_name, :key_format]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user