Class: Settings
- Inherits:
-
Object
- Object
- Settings
- Defined in:
- lib/propre/settings.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(path) ⇒ Settings
constructor
A new instance of Settings.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(path) ⇒ Settings
Returns a new instance of Settings.
6 7 8 9 10 11 12 13 14 |
# File 'lib/propre/settings.rb', line 6 def initialize(path) @path = path if !File.exist?(path) FileUtils.mkdir_p("#{Dir.home}/.config/Propre/") FileUtils.touch(path) end conf = YAML.load_file(path) @settings = conf ? conf : Hash.new end |
Instance Method Details
#get(key) ⇒ Object
16 17 18 |
# File 'lib/propre/settings.rb', line 16 def get(key) @settings[key] end |
#set(key, value) ⇒ Object
20 21 22 23 |
# File 'lib/propre/settings.rb', line 20 def set(key, value) @settings[key] = value File.open(@path, 'w') { |f| YAML.dump(@settings, f) } end |