Module: MadFlatter::HashInformable

Included in:
HashLoadable
Defined in:
lib/mad_flatter/hash_informable.rb

Overview

Flattens the provided Hash and assigns the results to the #hash_info attribute. If a namespace is provided, the namespace is prepended to the Hash key name.

Instance Method Summary collapse

Instance Method Details

#load_hash_info(hash:, namespace: nil, dig: [], hash_info: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mad_flatter/hash_informable.rb', line 8

def load_hash_info(hash:, namespace: nil, dig: [], hash_info: {})
  hash.each do |key, value|
    if value.is_a? Hash
      load_hash_info(hash: value,
        namespace: namespace,
        dig: dig << key,
        hash_info: hash_info)
      dig.pop
    else
      assign_hash_info(hash_info: hash_info,
        key: key,
        value: value,
        namespace: namespace,
        dig: dig)
    end

    next
  end

  hash_info
end