Class: BakerConfig
- Inherits:
-
Object
- Object
- BakerConfig
- Defined in:
- lib/baker/baker_config.rb
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args, key, value) ⇒ Object
- #flush ⇒ Object
-
#initialize(filename) ⇒ BakerConfig
constructor
A new instance of BakerConfig.
Constructor Details
#initialize(filename) ⇒ BakerConfig
Returns a new instance of BakerConfig.
5 6 7 8 9 10 11 12 13 |
# File 'lib/baker/baker_config.rb', line 5 def initialize(filename) @filename = filename if !File.exist?(filename) @config = {} else @config = YAML.load_file(filename) end end |
Instance Method Details
#[](*args) ⇒ Object
15 16 17 |
# File 'lib/baker/baker_config.rb', line 15 def [](*args) @config.dig(*args) end |
#[]=(*args, key, value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/baker/baker_config.rb', line 19 def []=(*args, key, value) last = args.inject(@config) do |memo, key| memo[key] ||= {} memo[key] end last[key] = value end |
#flush ⇒ Object
27 28 29 30 31 |
# File 'lib/baker/baker_config.rb', line 27 def flush File.open(@filename, 'w') do |f| f.write(@config.to_yaml) end end |