From 7e39d787333e8174e1dee32b8aede55ab70668ef Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 6 Nov 2020 11:34:16 +0000 Subject: [PATCH] Fix Long Method rubocop issue --- lib/action_dispatch/request.rb | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/action_dispatch/request.rb b/lib/action_dispatch/request.rb index 9d9dbd8449..b6f659e7dd 100644 --- a/lib/action_dispatch/request.rb +++ b/lib/action_dispatch/request.rb @@ -38,27 +38,31 @@ module ActionDispatch def deep_munge(hash, keys = []) return hash unless perform_deep_munge - hash.each do |k, v| - keys << k - case v - when Array - v.grep(Hash) { |x| deep_munge(x, keys) } - v.compact! - - # This patch removes the following lines - # if v.empty? - # hash[k] = nil - # ActiveSupport::Notifications.instrument("deep_munge.action_controller", - # keys: keys) - # end - when Hash - deep_munge(v, keys) - end - keys.pop + hash.each do |key, value| + deep_munge_value(key, value, keys) end hash end + + def deep_munge_value(key, value, keys) + keys << key + case value + when Array + value.grep(Hash) { |x| deep_munge(x, keys) } + value.compact! + + # This patch removes the following lines + # if v.empty? + # hash[k] = nil + # ActiveSupport::Notifications.instrument("deep_munge.action_controller", + # keys: keys) + # end + when Hash + deep_munge(value, keys) + end + keys.pop + end end end end