Class: Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = BYLD_CONF) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
# File 'lib/config.rb', line 6

def initialize(file = BYLD_CONF)
  File.write(file, '') unless File.exists? file
  
  @config = YAML.load(File.open(file)) || {}
  @file = file
end

Class Method Details

.load(file) ⇒ Object



13
14
15
# File 'lib/config.rb', line 13

def self.load(file)
  new(file)
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
# File 'lib/config.rb', line 17

def [](key)
  @config[key]
end

#merge!(hash) ⇒ Object



21
22
23
24
# File 'lib/config.rb', line 21

def merge!(hash)
  @config.merge!(hash.transform_keys(&:to_s))
  save!
end

#save!Object



26
27
28
29
30
# File 'lib/config.rb', line 26

def save!
  f = File.open(@file, 'w')
  f.write @config.to_yaml
  f.close
end