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.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/switchboard/settings.rb', line 7 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
34 35 36 |
# File 'lib/switchboard/settings.rb', line 34 def []=(key, value) set(key, value) end |
#get(key) ⇒ Object Also known as: []
18 19 20 |
# File 'lib/switchboard/settings.rb', line 18 def get(key) Switchboard::OPTIONS[key] || @config[key] || Switchboard::DEFAULT_OPTIONS[key] end |
#set(key, value) ⇒ Object
30 31 32 |
# File 'lib/switchboard/settings.rb', line 30 def set(key, value) @config[key] = value end |
#set!(key, value) ⇒ Object
24 25 26 27 28 |
# File 'lib/switchboard/settings.rb', line 24 def set!(key, value) set(key, value) write set_perms end |
#set_perms ⇒ Object
44 45 46 |
# File 'lib/switchboard/settings.rb', line 44 def set_perms File.chmod 0600, @path end |
#write ⇒ Object
38 39 40 41 42 |
# File 'lib/switchboard/settings.rb', line 38 def write open(@path, "w") do |f| f << @config.to_yaml end end |