mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add serialization_options
Prior to 0.9, @options was used to see the options passed to to_json. For some reason, with 0.9 the options were no longer passed and were entirely inaccessible within a Serializer. This restores the access by placing it in an attribute named serializer_options.
This commit is contained in:
parent
784eccd5bc
commit
d39a99d770
@ -9,11 +9,11 @@ module ActiveModel
|
||||
def as_json(options={})
|
||||
instrument('!serialize') do
|
||||
if root = options.fetch(:root, json_key)
|
||||
hash = { root => serializable_object }
|
||||
hash = { root => serializable_object(options) }
|
||||
hash.merge!(serializable_data)
|
||||
hash
|
||||
else
|
||||
serializable_object
|
||||
serializable_object(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -273,7 +273,10 @@ end
|
||||
end]
|
||||
end
|
||||
|
||||
attr_accessor :serialization_options
|
||||
|
||||
def serializable_object(options={})
|
||||
self.serialization_options = options
|
||||
return @wrap_in_array ? [] : nil if @object.nil?
|
||||
hash = attributes
|
||||
hash.merge! associations
|
||||
|
||||
Loading…
Reference in New Issue
Block a user