Class: ActionDispatch::Request::Utils

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/request/utils.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.deep_munge(hash, keys = []) ⇒ Object

Remove nils from the params hash


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'actionpack/lib/action_dispatch/request/utils.rb', line 10

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!
      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
  end

  hash
end