Class: Huebot::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(path = "~/.config/huebot") ⇒ Config

Returns a new instance of Config.



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

def initialize(path = "~/.config/huebot")
  @path = File.expand_path(path)
  @dir = File.dirname(@path)
  @dir_exists = File.exist? @dir
  @config = File.exist?(@path) ? YAML.load_file(@path) : {}
end

Instance Method Details

#[](attr) ⇒ Object



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

def [](attr)
  @config[attr.to_s]
end

#[]=(attr, val) ⇒ Object



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

def []=(attr, val)
  if val.nil?
    @config.delete(attr.to_s)
  else
    @config[attr.to_s] = val
  end
  write
end

#clearObject



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

def clear
  @config.clear
  write
end