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:
Robin Daugherty 2014-10-12 01:08:47 -04:00
parent 784eccd5bc
commit d39a99d770
2 changed files with 5 additions and 2 deletions

View File

@ -9,11 +9,11 @@ module ActiveModel
def as_json(options={}) def as_json(options={})
instrument('!serialize') do instrument('!serialize') do
if root = options.fetch(:root, json_key) if root = options.fetch(:root, json_key)
hash = { root => serializable_object } hash = { root => serializable_object(options) }
hash.merge!(serializable_data) hash.merge!(serializable_data)
hash hash
else else
serializable_object serializable_object(options)
end end
end end
end end

View File

@ -273,7 +273,10 @@ end
end] end]
end end
attr_accessor :serialization_options
def serializable_object(options={}) def serializable_object(options={})
self.serialization_options = options
return @wrap_in_array ? [] : nil if @object.nil? return @wrap_in_array ? [] : nil if @object.nil?
hash = attributes hash = attributes
hash.merge! associations hash.merge! associations