Class: Configy::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/configy/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(filename, section, load_path, cache_config = false) ⇒ Base
Returns a new instance of Base.
5
6
7
8
9
10
|
# File 'lib/configy/base.rb', line 5
def initialize(filename, section, load_path, cache_config=false)
@load_path = load_path
@section = section
@filename = filename
@cache_config = cache_config
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
|
# File 'lib/configy/base.rb', line 12
def method_missing(name, *args, &block)
if args.size.zero?
reload if !cache_config? && stale?
config[name]
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
21
22
23
|
# File 'lib/configy/base.rb', line 21
def [](key)
config[key]
end
|
#cache_config? ⇒ Boolean
31
32
33
|
# File 'lib/configy/base.rb', line 31
def cache_config?
@cache_config
end
|
#reload ⇒ Object
25
26
27
28
29
|
# File 'lib/configy/base.rb', line 25
def reload
@config = config_file.config.merge(local_config_file.config).tap do |c|
c.mtime = most_recent_mtime
end
end
|