File: utils.rb

package info (click to toggle)
rails 2%3A4.1.8-1%2Bdeb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 22,132 kB
  • ctags: 27,642
  • sloc: ruby: 172,886; sql: 43; yacc: 43; sh: 14; makefile: 12
file content (35 lines) | stat: -rw-r--r-- 824 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module ActionDispatch
  class Request < Rack::Request
    class Utils # :nodoc:

      mattr_accessor :perform_deep_munge
      self.perform_deep_munge = true

      class << self
        # Remove nils from the params hash
        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
      end
    end
  end
end