Class: Chronicler::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



9
10
11
# File 'lib/chronicler/config.rb', line 9

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/chronicler/config.rb', line 3

def file
  @file
end

Class Method Details

.[](file) ⇒ Object



5
6
7
# File 'lib/chronicler/config.rb', line 5

def self.[](file)
  new(file)
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  split(key).inject(load_file){|h, k| (h || {})[k]}
end

#[]=(key, value) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/chronicler/config.rb', line 17

def []=(key, value)
  config = load_file

  keys = split(key)
  hash = keys[0..-2].inject(config){|h, k| h[k] ||= {}}
  hash[keys.last] = value

  dump_file config.reject{|k, v| v.nil?}
end