Class: Gel::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



4
5
6
7
8
# File 'lib/gel/config.rb', line 4

def initialize
  @root = File.expand_path("~/.config/gel")
  @path = File.join(@root, "config")
  @config = nil
end

Instance Method Details

#[](group = nil, key) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/gel/config.rb', line 14

def [](group = nil, key)
  if group.nil?
    group, key = key.split(".", 2)
  end

  (group ? (config[group.to_s] || {}) : config)[key.to_s]
end

#[]=(group = nil, key, value) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/gel/config.rb', line 22

def []=(group = nil, key, value)
  if group.nil?
    group, key = key.split(".", 2)
  end

  (group ? (config[group.to_s] ||= {}) : config)[key.to_s] = value.to_s

  write(config)
end

#configObject



10
11
12
# File 'lib/gel/config.rb', line 10

def config
  @config ||= read
end