From 7e14c16cc099c9effeedcb097484c7c3b64e15f9 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Fri, 22 May 2020 00:04:31 +0100 Subject: [PATCH] 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. --- activemodel/lib/active_model/serialization.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index 6a2ae6540e..4ed6e71df6 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -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|