Class: BakerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/baker/baker_config.rb

Instance Method Summary collapse

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

#flushObject



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