Class: LanGrove::ConfigItem

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/ext/config_item.rb

Class Method Summary collapse

Class Method Details

.get(config_hash, key_array, mandatory = true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/langrove/ext/config_item.rb', line 12

def self.get(config_hash, key_array, mandatory = true)
  
  # raise ConfigException.new("match")
  
  hash = config_hash
  
  key_array.each do |key|
    
    if mandatory != false then
      # raises a config exception if the item isnt present
      raise ConfigException.new("Missing config item '#{key}'") unless hash.has_key?(key)
    
      # raises a config exception if the nested item isnt present NEITHER NOT
     # raise ConfigException.new("Missing config item '#{key}'") if hash[key].empty?
    
      hash = hash[key]
    
      # raises a config exception if the key isnt present BLANK NEITHER
      raise ConfigException.new("Missing config item '#{key}'") if hash == "" 
    
    end
    
  end
  
  return hash
  
end