mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Use a third argument to pass serializer_options
This commit is contained in:
parent
c04d452823
commit
e273a2fb37
@ -380,8 +380,7 @@ module ActiveModel
|
|||||||
options[:value] ||= send(name)
|
options[:value] ||= send(name)
|
||||||
options[:embed] = _embed unless options.key?(:embed)
|
options[:embed] = _embed unless options.key?(:embed)
|
||||||
options[:include] = _root_embed unless options.key?(:include)
|
options[:include] = _root_embed unless options.key?(:include)
|
||||||
options[:serializer_options] = self.options
|
association = association_class.new(name, options, self.options)
|
||||||
association = association_class.new(name, options)
|
|
||||||
|
|
||||||
if association.embed_ids?
|
if association.embed_ids?
|
||||||
node[association.key] =
|
node[association.key] =
|
||||||
|
|||||||
@ -2,9 +2,10 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
module Associations #:nodoc:
|
module Associations #:nodoc:
|
||||||
class Config #:nodoc:
|
class Config #:nodoc:
|
||||||
def initialize(name, options={})
|
def initialize(name, options={}, serializer_options={})
|
||||||
@name = name
|
@name = name
|
||||||
@options = options
|
@options = options
|
||||||
|
@serializer_options = serializer_options
|
||||||
end
|
end
|
||||||
|
|
||||||
def target_serializer
|
def target_serializer
|
||||||
@ -48,15 +49,15 @@ module ActiveModel
|
|||||||
|
|
||||||
def find_serializable(object)
|
def find_serializable(object)
|
||||||
if target_serializer
|
if target_serializer
|
||||||
target_serializer.new(object, options[:serializer_options])
|
target_serializer.new(object, serializer_options)
|
||||||
elsif object.respond_to?(:active_model_serializer) && (ams = object.active_model_serializer)
|
elsif object.respond_to?(:active_model_serializer) && (ams = object.active_model_serializer)
|
||||||
ams.new(object, options[:serializer_options])
|
ams.new(object, serializer_options)
|
||||||
else
|
else
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :options
|
attr_reader :options, :serializer_options
|
||||||
end
|
end
|
||||||
|
|
||||||
class HasMany < Config #:nodoc:
|
class HasMany < Config #:nodoc:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user