Class: Flamingo::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/flamingo/config.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Config
Returns a new instance of Config.
8
9
10
|
# File 'lib/flamingo/config.rb', line 8
def initialize(hash={})
@data = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ 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
|
# File 'lib/flamingo/config.rb', line 12
def method_missing(name,*args,&block)
if name.to_s =~ /(.+)=$/
@data[$1] = *args
else
value = @data[name.to_s]
if value.is_a?(Hash)
self.class.new(value)
elsif value.nil? || empty_config?(value)
if !args.empty?
args.length == 1 ? args[0] : args
elsif block_given?
yield
else
value = self.class.new
@data[name.to_s] = value
value
end
else
value
end
end
end
|
Class Method Details
.load(file) ⇒ Object
4
5
6
|
# File 'lib/flamingo/config.rb', line 4
def self.load(file)
new(YAML.load(IO.read(file)))
end
|
Instance Method Details
#empty? ⇒ Boolean
42
43
44
|
# File 'lib/flamingo/config.rb', line 42
def empty?
@data.empty?
end
|
#respond_to?(name) ⇒ Boolean
38
39
40
|
# File 'lib/flamingo/config.rb', line 38
def respond_to?(name)
true
end
|