Class: Configy::ConfigStore
- Inherits:
-
Object
- Object
- Configy::ConfigStore
- Defined in:
- lib/configy/config_store.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access to the stored configs.
-
#compile(section) ⇒ Object
Returns a new ConfigStore by merging ‘common` with `section`.
-
#initialize(config) ⇒ ConfigStore
constructor
Takes a Hash as input.
-
#merge(other) ⇒ Object
Merges two ConfigStore objects together by merging their hashes.
- #to_hash ⇒ Object
Constructor Details
#initialize(config) ⇒ ConfigStore
Takes a Hash as input
28 29 30 |
# File 'lib/configy/config_store.rb', line 28 def initialize(config) @config = Hashie::Mash.new( config && config.to_hash || {} ) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
24 25 26 |
# File 'lib/configy/config_store.rb', line 24 def config @config end |
#mtime ⇒ Object
Returns the value of attribute mtime.
25 26 27 |
# File 'lib/configy/config_store.rb', line 25 def mtime @mtime end |
Instance Method Details
#[](key) ⇒ Object
Access to the stored configs
46 47 48 49 50 51 52 53 54 |
# File 'lib/configy/config_store.rb', line 46 def [](key) key = key.to_s if @config.key?(key) @config[key] else raise ConfigParamNotFound, key end end |
#compile(section) ⇒ Object
Returns a new ConfigStore by merging ‘common` with `section`
33 34 35 36 37 38 |
# File 'lib/configy/config_store.rb', line 33 def compile(section) common = @config['common'] || {} selected = @config[section] || {} self.class.new( common.deep_merge(selected) ) end |
#merge(other) ⇒ Object
Merges two ConfigStore objects together by merging their hashes
41 42 43 |
# File 'lib/configy/config_store.rb', line 41 def merge(other) self.class.new( config.deep_merge(other.config) ) end |
#to_hash ⇒ Object
56 57 58 |
# File 'lib/configy/config_store.rb', line 56 def to_hash @config end |