Class: Configgler::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/configgler/config.rb

Defined Under Namespace

Classes: ConfigElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, *args) ⇒ Config

Returns a new instance of Config.



9
10
11
# File 'lib/configgler/config.rb', line 9

def initialize(file,*args)
    @config = YAML.load(File.new(File.join(args.flatten.join('/'),file)))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



13
14
15
16
# File 'lib/configgler/config.rb', line 13

def method_missing(name,*args)
    el = ConfigElement.new(@config,name.to_s)
    el.element.is_a?(Hash) ? el : el.value
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/configgler/config.rb', line 7

def config
  @config
end

Instance Method Details

#get(*args) ⇒ Object



26
27
28
# File 'lib/configgler/config.rb', line 26

def get(*args)
    get_by_array(args)
end

#get_by_array(args = []) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/configgler/config.rb', line 18

def get_by_array(args=[])
    c = @config[args.shift.to_s] 
    until args.length == 0 
        c = c[args.shift.to_s]
    end
    c
end