Class: Bbiff::Settings
- Inherits:
-
Object
- Object
- Bbiff::Settings
- Defined in:
- lib/bbiff/settings.rb
Constant Summary collapse
- APP_NAME =
'bbiff'
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ Settings
Returns a new instance of Settings.
11 12 13 14 15 |
# File 'lib/bbiff/settings.rb', line 11 def initialize @current = default.dup @config_dir = "#{ ENV['HOME'] }/.config/#{ APP_NAME }" load end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
7 8 9 |
# File 'lib/bbiff/settings.rb', line 7 def current @current end |
Instance Method Details
#default ⇒ Object
17 18 19 |
# File 'lib/bbiff/settings.rb', line 17 def default { 'delay_seconds' => 10, 'bbiff_show' => 'bbiff-show' } end |
#load ⇒ Object
21 22 23 24 25 26 |
# File 'lib/bbiff/settings.rb', line 21 def load if File.readable?("#{@config_dir}/settings.tml") prefs = TOML.load_file("#{@config_dir}/settings.tml") self.current = current.merge(prefs) end end |
#save ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/bbiff/settings.rb', line 28 def save FileUtils.mkdir_p(@config_dir) prefs = (current.to_a - default.to_a).to_h File.open("#{@config_dir}/settings.tml", 'w') do |f| f.write(TOML.dump(prefs)) end end |