Class: V1gittools::DeepHashWithIndifferentAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/v1gittools/deep_hash_with_indifferent_access.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.convert_array(arr) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/v1gittools/deep_hash_with_indifferent_access.rb', line 27

def self.convert_array(arr)
  new_array = []
  arr.each do |value|
    if value.is_a? Hash
      new_array << (convert_hash value)
    elsif value.is_a? Array
      new_array << (convert_array value)
    else
      new_array << value
    end
  end
  new_array
end

.convert_hash(hash) ⇒ Object

HashWithIndifferentAccess does not convert the hash deeply so we must do this ourselves :(



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/v1gittools/deep_hash_with_indifferent_access.rb', line 13

def self.convert_hash(hash)
  new_hash = Thor::CoreExt::HashWithIndifferentAccess.new
  hash.each do |key, value|
    if value.is_a? Hash
      new_hash[key] = convert_hash value
    elsif value.is_a? Array
      new_hash[key] = convert_array value
    else
      new_hash[key] = value
    end
  end
  new_hash
end