Class: Tarot::Config
- Inherits:
-
Object
- Object
- Tarot::Config
- Defined in:
- lib/tarot.rb
Instance Attribute Summary collapse
-
#config_files ⇒ Object
Returns the value of attribute config_files.
-
#env ⇒ Object
Returns the value of attribute env.
-
#yaml ⇒ Object
Returns the value of attribute yaml.
Instance Method Summary collapse
- #get(key, default = nil, env = @env) ⇒ Object
-
#initialize(files, env) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(files, env) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tarot.rb', line 7 def initialize(files, env) @config_files = files @config_files = [@config_files] if @config_files.is_a? String @yaml = {} @config_files.each do |file| yaml = YAML::load(File.open(file).read.untaint).stringify_keys! recursive_merge @yaml, yaml end add_mm @yaml @config_cache = {} @env = env end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
47 48 49 |
# File 'lib/tarot.rb', line 47 def method_missing(method, *args) @yaml[args[1] || @env].send method, *args end |
Instance Attribute Details
#config_files ⇒ Object
Returns the value of attribute config_files.
6 7 8 |
# File 'lib/tarot.rb', line 6 def config_files @config_files end |
#env ⇒ Object
Returns the value of attribute env.
6 7 8 |
# File 'lib/tarot.rb', line 6 def env @env end |
#yaml ⇒ Object
Returns the value of attribute yaml.
6 7 8 |
# File 'lib/tarot.rb', line 6 def yaml @yaml end |
Instance Method Details
#get(key, default = nil, env = @env) ⇒ Object
20 21 22 23 |
# File 'lib/tarot.rb', line 20 def get(key, default = nil, env = @env) @config_cache[env] ||= {} @config_cache[env][key] ||= key.split('.').inject(@yaml[env || @env]) {|e, part| e.try(:[], part) } || default end |