Class: Adam::Configuration
- Inherits:
-
Object
- Object
- Adam::Configuration
show all
- Defined in:
- lib/adam/configuration.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
5
6
7
8
|
# File 'lib/adam/configuration.rb', line 5
def initialize(data = {})
@data = {}
populate!(data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/adam/configuration.rb', line 28
def method_missing(sym, *args)
if sym.to_s =~ /(.+)=$/
self[$1] = args.first
else
self[sym]
end
end
|
Instance Method Details
#[](key) ⇒ Object
16
17
18
|
# File 'lib/adam/configuration.rb', line 16
def [](key)
@data[key.to_sym]
end
|
#[]=(key, value) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/adam/configuration.rb', line 20
def []=(key, value)
if value.class == Hash
@data[key.to_sym] = Configuration.new(value)
else
@data[key.to_sym] = value
end
end
|
#populate!(data) ⇒ Object
10
11
12
13
14
|
# File 'lib/adam/configuration.rb', line 10
def populate!(data)
data.each do |key, value|
self[key] = value
end
end
|