mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Revert "Merge branch 'context'"
This reverts commit1bd8180a94, reversing changes made to9bb32331f4.
This commit is contained in:
@@ -65,21 +65,11 @@ module ActionController
|
||||
options = default_serializer_options.merge(options)
|
||||
|
||||
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
|
||||
options[:context] = build_context_from options[:context]
|
||||
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
||||
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
|
||||
|
||||
@@ -14,14 +14,14 @@ module ActiveModel
|
||||
|
||||
def initialize(object, options={})
|
||||
@object = object
|
||||
@context = options[:context] || {}
|
||||
@scope = options[:scope]
|
||||
@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, :root, :meta_key, :meta
|
||||
attr_accessor :object, :scope, :root, :meta_key, :meta
|
||||
|
||||
def json_key
|
||||
if root.nil?
|
||||
@@ -33,7 +33,7 @@ module ActiveModel
|
||||
|
||||
def serializer_for(item)
|
||||
serializer_class = @each_serializer || Serializer.serializer_for(item) || DefaultSerializer
|
||||
serializer_class.new(item, context: context)
|
||||
serializer_class.new(item, scope: scope)
|
||||
end
|
||||
|
||||
def serializable_object
|
||||
|
||||
@@ -103,13 +103,13 @@ end
|
||||
|
||||
def initialize(object, options={})
|
||||
@object = object
|
||||
@context = options[:context] || {}
|
||||
@scope = options[:scope]
|
||||
@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, :root, :meta_key, :meta
|
||||
attr_accessor :object, :scope, :root, :meta_key, :meta
|
||||
|
||||
def json_key
|
||||
if root == true || root.nil?
|
||||
@@ -166,7 +166,7 @@ end
|
||||
|
||||
def build_serializer(association)
|
||||
object = send(association.name)
|
||||
association.build_serializer(object, context: context)
|
||||
association.build_serializer(object, scope: scope)
|
||||
end
|
||||
|
||||
def serialize(association)
|
||||
|
||||
Reference in New Issue
Block a user