Module: ExtraHashMethods

Defined in:
lib/blinkbox/common_messaging/header_detectors/detect_remote_uris.rb

Instance Method Summary collapse

Instance Method Details

#deep_key_select(parent_key: "", &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/blinkbox/common_messaging/header_detectors/detect_remote_uris.rb', line 20

def deep_key_select(parent_key: "", &block)
  keys = []
  keys.push parent_key if block.call(self)
  self.each do |k, v|
    case v
    when Hash
      v.extend(ExtraHashMethods).deep_key_select(parent_key: k, &block).each do |hit|
        keys.push [parent_key, hit].join(".").sub(/^\./,"")
      end
    when Array
      v.each_with_index do |item, i|
        if item.is_a? Hash
          item.extend(ExtraHashMethods).deep_key_select(parent_key: "#{k}[#{i}]", &block).each do |hit|
            keys.push [parent_key, hit].join(".").sub(/^\./,"")
          end
        end
      end
    end
  end
  keys
end