Class: Confuse::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/confuse/config.rb
Instance Method Summary
collapse
Constructor Details
#initialize(definition, source) ⇒ Config
Returns a new instance of Config.
5
6
7
8
|
# File 'lib/confuse/config.rb', line 5
def initialize(definition, source)
@definition = definition
@source = source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args) ⇒ Object
14
15
16
|
# File 'lib/confuse/config.rb', line 14
def method_missing(name, *_args)
self[name] if respond_to?(name)
end
|
Instance Method Details
#[](name) ⇒ Object
18
19
20
21
|
# File 'lib/confuse/config.rb', line 18
def [](name)
namespace, key = @definition.namespace_and_key(name)
lookup(namespace, key)
end
|
#check ⇒ Object
check items have a value. Will raise Undefined error if a required item has no value.
29
30
31
32
33
34
35
|
# File 'lib/confuse/config.rb', line 29
def check
@definition.namespaces.each do |(namespace, ns)|
ns.items.each do |key, _|
lookup(namespace, key)
end
end
end
|
#lookup(namespace, key) ⇒ Object
23
24
25
|
# File 'lib/confuse/config.rb', line 23
def lookup(namespace, key)
@source[namespace, key] || @definition.default(namespace, key)
end
|
#respond_to?(name) ⇒ Boolean
10
11
12
|
# File 'lib/confuse/config.rb', line 10
def respond_to?(name)
@definition.defines?(name) || super
end
|