Merge pull request #965 from bf4/serialization_options_default_nil

options fedault valueserializable_hash and as_json
This commit is contained in:
João Moura 2015-06-25 18:32:52 -03:00
commit 1bb1724b5d
4 changed files with 10 additions and 8 deletions

View File

@ -16,11 +16,11 @@ module ActiveModel
@options = options
end
def serializable_hash(options = {})
def serializable_hash(options = nil)
raise NotImplementedError, 'This is an abstract method. Should be implemented at the concrete adapter.'
end
def as_json(options = {})
def as_json(options = nil)
hash = serializable_hash(options)
include_meta(hash) unless self.class == FlattenJson
hash

View File

@ -4,9 +4,10 @@ module ActiveModel
class Serializer
class Adapter
class Json < Adapter
def serializable_hash(options = {})
def serializable_hash(options = nil)
options ||= {}
if serializer.respond_to?(:each)
@result = serializer.map{|s| FlattenJson.new(s).serializable_hash }
@result = serializer.map{|s| FlattenJson.new(s).serializable_hash(options) }
else
@hash = {}

View File

@ -15,10 +15,11 @@ module ActiveModel
end
end
def serializable_hash(options = {})
def serializable_hash(options = nil)
options = {}
if serializer.respond_to?(:each)
serializer.each do |s|
result = self.class.new(s, @options.merge(fieldset: @fieldset)).serializable_hash
result = self.class.new(s, @options.merge(fieldset: @fieldset)).serializable_hash(options)
@hash[:data] << result[:data]
if result[:included]
@ -27,7 +28,7 @@ module ActiveModel
end
end
else
@hash[:data] = attributes_for_serializer(serializer, @options)
@hash[:data] = attributes_for_serializer(serializer, options)
add_resource_relationships(@hash[:data], serializer)
end
@hash

View File

@ -2,7 +2,7 @@ module ActiveModel
class Serializer
class Adapter
class Null < Adapter
def serializable_hash(options = {})
def serializable_hash(options = nil)
{}
end
end