Class: Switchboard::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/switchboard/settings.rb

Constant Summary collapse

DEFAULT_PATH =
File.join(ENV["HOME"], ".switchboardrc")

Instance Method Summary collapse

Constructor Details

#initialize(path = DEFAULT_PATH) ⇒ Settings

Returns a new instance of Settings.



5
6
7
8
9
10
11
12
13
# File 'lib/switchboard/settings.rb', line 5

def initialize(path = DEFAULT_PATH)
  @path = path

  if File.exists?(path)
    @config = YAML.load(File.read(path))
  end

  @config ||= {}
end

Instance Method Details

#[]=(key, value) ⇒ Object



30
31
32
# File 'lib/switchboard/settings.rb', line 30

def []=(key, value)
  set(key, value)
end

#get(key) ⇒ Object Also known as: []



15
16
17
# File 'lib/switchboard/settings.rb', line 15

def get(key)
  Switchboard::Command::OPTIONS[key] || @config[key] || Switchboard::Command::DEFAULT_OPTIONS[key]
end

#set(key, value) ⇒ Object



26
27
28
# File 'lib/switchboard/settings.rb', line 26

def set(key, value)
  @config[key] = value
end

#set!(key, value) ⇒ Object



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

def set!(key, value)
  set(key, value)
  write
end

#writeObject



34
35
36
37
38
# File 'lib/switchboard/settings.rb', line 34

def write
  open(@path, "w") do |f|
    f << @config.to_yaml
  end
end