Class: Switchboard::Settings
- Inherits:
-
Object
- Object
- Switchboard::Settings
- Defined in:
- lib/switchboard/settings.rb
Constant Summary collapse
- DEFAULT_PATH =
File.join(ENV["HOME"], ".switchboardrc")
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #get(key) ⇒ Object (also: #[])
-
#initialize(path = DEFAULT_PATH) ⇒ Settings
constructor
A new instance of Settings.
- #set(key, value) ⇒ Object
- #set!(key, value) ⇒ Object
- #set_perms ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(path = DEFAULT_PATH) ⇒ Settings
Returns a new instance of Settings.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/switchboard/settings.rb', line 5 def initialize(path = DEFAULT_PATH) @path = path if File.exists?(path) set_perms @config = YAML.load(File.read(path)) end @config ||= {} end |
Instance Method Details
#[]=(key, value) ⇒ Object
32 33 34 |
# File 'lib/switchboard/settings.rb', line 32 def []=(key, value) set(key, value) end |
#get(key) ⇒ Object Also known as: []
16 17 18 |
# File 'lib/switchboard/settings.rb', line 16 def get(key) Switchboard::Command::OPTIONS[key] || @config[key] || Switchboard::Command::DEFAULT_OPTIONS[key] end |
#set(key, value) ⇒ Object
28 29 30 |
# File 'lib/switchboard/settings.rb', line 28 def set(key, value) @config[key] = value end |
#set!(key, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/switchboard/settings.rb', line 22 def set!(key, value) set(key, value) write set_perms end |
#set_perms ⇒ Object
42 43 44 |
# File 'lib/switchboard/settings.rb', line 42 def set_perms File.chmod 0600, @path end |
#write ⇒ Object
36 37 38 39 40 |
# File 'lib/switchboard/settings.rb', line 36 def write open(@path, "w") do |f| f << @config.to_yaml end end |