mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Allow to pass context around serializers
This commit is contained in:
@@ -103,13 +103,14 @@ 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, :scope, :root, :meta_key, :meta
|
||||
attr_accessor :object, :context, :scope, :root, :meta_key, :meta
|
||||
|
||||
def json_key
|
||||
if root == true || root.nil?
|
||||
@@ -166,7 +167,7 @@ end
|
||||
|
||||
def build_serializer(association)
|
||||
object = send(association.name)
|
||||
association.build_serializer(object, scope: scope)
|
||||
association.build_serializer(object, context: context, scope: scope)
|
||||
end
|
||||
|
||||
def serialize(association)
|
||||
|
||||
Reference in New Issue
Block a user