Class: Bushido::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/bushido/utils.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.array_helper(array, proc) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bushido/utils.rb', line 8

def array_helper(array, proc)
  array.collect do |value|
    if value.kind_of?( Hash  )
      deep_process_hash_keys(value, proc)
    elsif value.kind_of?( Array )
      array_helper(array)
    else
      value
    end
  end
end

.deep_process_hash_keys(input_hash, proc) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bushido/utils.rb', line 20

def deep_process_hash_keys(input_hash, proc)
  hash = {}
  input_hash.keys.each do |key|
    _key = proc.call(key)
    if input_hash[key].kind_of?(Hash)
      hash[_key] = deep_process_hash_keys(input_hash[key], proc)
    elsif input_hash[key].kind_of?(Array)
      hash[_key] = array_helper(input_hash[key], proc)
    else
      hash[_key] = input_hash[key]
    end
  end

  hash
end

.deep_stringify_hash_keys(input_hash) ⇒ Object



44
45
46
# File 'lib/bushido/utils.rb', line 44

def deep_stringify_hash_keys(input_hash)
  deep_process_hash_keys(input_hash, Proc.new { |key| key.to_s })
end

.deep_symbolize_hash_keys(input_hash) ⇒ Object



40
41
42
# File 'lib/bushido/utils.rb', line 40

def deep_symbolize_hash_keys(input_hash)
  deep_process_hash_keys(input_hash, Proc.new { |key| key.to_sym })
end

.deep_underscore_hash_keys(input_hash) ⇒ Object



36
37
38
# File 'lib/bushido/utils.rb', line 36

def deep_underscore_hash_keys(input_hash)
  deep_process_hash_keys(input_hash, Proc.new { |key| key.to_s.underscore })
end

.normalize_keys(input_hash) ⇒ Object



48
49
50
# File 'lib/bushido/utils.rb', line 48

def normalize_keys(input_hash)
  deep_symbolize_hash_keys(deep_underscore_hash_keys(input_hash))
end

.refresh_env!Object

TODO: Make this update all the available ENV variables



5
6
# File 'lib/bushido/utils.rb', line 5

def refresh_env!
end