Class: EAAL::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.



4
5
6
7
# File 'lib/eaal/config.rb', line 4

def initialize(data={})
  @data = {}
  update!(data)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/eaal/config.rb', line 27

def method_missing(sym, *args)
  if sym.to_s =~ /(.+)=$/
    self[$1] = args.first
  else
    self[sym]
  end
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/eaal/config.rb', line 15

def [](key)
  @data[key.to_sym]
end

#[]=(key, value) ⇒ Object



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

def []=(key, value)
  if value.class == Hash
    @data[key.to_sym] = Config.new(value)
  else
    @data[key.to_sym] = value
  end
end

#update!(data) ⇒ Object



9
10
11
12
13
# File 'lib/eaal/config.rb', line 9

def update!(data)
  data.each do |key, value|
    self[key] = value
  end
end