Optimise serializable_hash when options are empty

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

We can still get most of the benefit by applying the optimisation from
7b3919774252f99e55e6b6ec370aafc42adca2b2 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

@ -123,7 +123,7 @@ module Serialization
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 @@ def serializable_add_includes(options = {}) #:nodoc:
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|