mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Nest scope under context option
This commit is contained in:
committed by
Santiago Pastorino
parent
8bd2542ed2
commit
0d8ef2b165
@@ -65,7 +65,7 @@ module ActionController
|
||||
options = default_serializer_options.merge(options)
|
||||
|
||||
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
|
||||
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
||||
options[:context] = { scope: serialization_scope }.merge!(options[:context] || {})
|
||||
options[:resource_name] = controller_name if resource.respond_to?(:to_ary)
|
||||
|
||||
serializer.new(resource, options)
|
||||
|
||||
@@ -14,15 +14,14 @@ module ActiveModel
|
||||
|
||||
def initialize(object, options={})
|
||||
@object = object
|
||||
@context = options[:context]
|
||||
@scope = options[:scope]
|
||||
@context = options[:context] || {}
|
||||
@root = options.fetch(:root, self.class._root)
|
||||
@meta_key = options[:meta_key] || :meta
|
||||
@meta = options[@meta_key]
|
||||
@each_serializer = options[:each_serializer]
|
||||
@resource_name = options[:resource_name]
|
||||
end
|
||||
attr_accessor :object, :context, :scope, :root, :meta_key, :meta
|
||||
attr_accessor :object, :context, :root, :meta_key, :meta
|
||||
|
||||
def json_key
|
||||
if root.nil?
|
||||
@@ -34,7 +33,7 @@ module ActiveModel
|
||||
|
||||
def serializer_for(item)
|
||||
serializer_class = @each_serializer || Serializer.serializer_for(item) || DefaultSerializer
|
||||
serializer_class.new(item, context: context, scope: scope)
|
||||
serializer_class.new(item, context: context)
|
||||
end
|
||||
|
||||
def serializable_object
|
||||
|
||||
@@ -103,14 +103,13 @@ end
|
||||
|
||||
def initialize(object, options={})
|
||||
@object = object
|
||||
@context = options[:context]
|
||||
@scope = options[:scope]
|
||||
@context = options[:context] || {}
|
||||
@root = options.fetch(:root, self.class._root)
|
||||
@meta_key = options[:meta_key] || :meta
|
||||
@meta = options[@meta_key]
|
||||
@wrap_in_array = options[:_wrap_in_array]
|
||||
end
|
||||
attr_accessor :object, :context, :scope, :root, :meta_key, :meta
|
||||
attr_accessor :object, :context, :root, :meta_key, :meta
|
||||
|
||||
def json_key
|
||||
if root == true || root.nil?
|
||||
@@ -167,7 +166,7 @@ end
|
||||
|
||||
def build_serializer(association)
|
||||
object = send(association.name)
|
||||
association.build_serializer(object, context: context, scope: scope)
|
||||
association.build_serializer(object, context: context)
|
||||
end
|
||||
|
||||
def serialize(association)
|
||||
|
||||
Reference in New Issue
Block a user