Class: Huebot::CLI::Config

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

Instance Method Summary collapse

Constructor Details

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



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

def initialize(path = "~/.config/huebot")
  @path = File.expand_path(path)
  @dir = File.dirname(@path)
  @dir_exists = File.exist? @dir
  reload
end

Instance Method Details

#[](attr) ⇒ Object



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

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

#[]=(attr, val) ⇒ Object



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

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

#clearObject



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

def clear
  @config.clear
  write
end

#reloadObject



32
33
34
# File 'lib/huebot/cli/config.rb', line 32

def reload
  @config = File.exist?(@path) ? YAML.load_file(@path) : {}
end