Class: Tagcrumbs::ConfigStore
- Inherits:
-
Object
- Object
- Tagcrumbs::ConfigStore
- Defined in:
- lib/tagcrumbs/config_store.rb
Overview
Use the ConfigStore to save configuration options to a yaml file
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.load(filename) ⇒ Object
Load a filename and read it with YAML.
Instance Method Summary collapse
-
#initialize(filename, options = {}) ⇒ ConfigStore
constructor
A new instance of ConfigStore.
-
#save(file = filename) ⇒ Object
Save the current options into the file in YAML format.
-
#update(c = {}) ⇒ Object
Update the current options and save the file.
Constructor Details
#initialize(filename, options = {}) ⇒ ConfigStore
Returns a new instance of ConfigStore.
6 7 8 9 |
# File 'lib/tagcrumbs/config_store.rb', line 6 def initialize(filename, ={}) @filename = filename @options = end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/tagcrumbs/config_store.rb', line 4 def filename @filename end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/tagcrumbs/config_store.rb', line 4 def @options end |
Class Method Details
.load(filename) ⇒ Object
Load a filename and read it with YAML
12 13 14 15 |
# File 'lib/tagcrumbs/config_store.rb', line 12 def self.load(filename) config = File.exist?(filename) ? YAML::load(open(filename)) : {} new(filename, config) end |
Instance Method Details
#save(file = filename) ⇒ Object
Save the current options into the file in YAML format
25 26 27 28 |
# File 'lib/tagcrumbs/config_store.rb', line 25 def save(file = filename) File.open(file, 'w') { |f| f.write(YAML.dump(@options.stringify_keys)) } self end |
#update(c = {}) ⇒ Object
Update the current options and save the file
18 19 20 21 22 |
# File 'lib/tagcrumbs/config_store.rb', line 18 def update(c={}) @options.merge!(c) save self end |