Optimise serializable_hash when options are empty

This reverts 8538dfdc08, which broke the
activemodel-serializers-xml gem.

We can still get most of the benefit by applying the optimisation from
7b39197742 to empty hashes as well as nil.
This has the additional benefit of retaining the optimisation when the
user passes an empty options hash.
This commit is contained in:
Eugene Kenny 2020-05-22 00:04:31 +01:00
parent e4b6c719cd
commit 7e14c16cc0
1 changed files with 2 additions and 2 deletions

View File

@ -123,7 +123,7 @@ module ActiveModel
def serializable_hash(options = nil)
attribute_names = attributes.keys
return serializable_attributes(attribute_names) unless options
return serializable_attributes(attribute_names) if options.blank?
if only = options[:only]
attribute_names &= Array(only).map(&:to_s)
@ -179,7 +179,7 @@ module ActiveModel
return unless includes = options[:include]
unless includes.is_a?(Hash)
includes = Hash[Array(includes).flat_map { |n| n.is_a?(Hash) ? n.to_a : [[n, nil]] }]
includes = Hash[Array(includes).flat_map { |n| n.is_a?(Hash) ? n.to_a : [[n, {}]] }]
end
includes.each do |association, opts|