Class: Precursor::ConfigRoot
- Inherits:
-
Object
- Object
- Precursor::ConfigRoot
- Defined in:
- lib/config_root.rb
Overview
Root class to access config vaults
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(vaults, key_options) ⇒ ConfigRoot
constructor
A new instance of ConfigRoot.
- #resolve(str) ⇒ Object
Constructor Details
#initialize(vaults, key_options) ⇒ ConfigRoot
Returns a new instance of ConfigRoot.
6 7 8 9 10 11 12 13 |
# File 'lib/config_root.rb', line 6 def initialize(vaults, ) @vaults = vaults = @vaults.each do |v| v.load(self) end end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/config_root.rb', line 15 def [](key) key_vault = @vaults.find { |v| v.key? key } value = key_vault.value key unless key_vault.nil? value = get_default(key) if key_vault.nil? value.is_a?(String) ? resolve(value) : value end |
#resolve(str) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/config_root.rb', line 24 def resolve(str) res = str until (m = res.match(VAR_PATTERN)).nil? k = m[1] v = self[k.to_sym] res = res.sub("${#{k}}", v.to_s) end res end |