Class: TeamboxThingsSync::ConfigStore
- Inherits:
-
Object
- Object
- TeamboxThingsSync::ConfigStore
- Defined in:
- lib/teambox-things-sync/config_store.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(*keys) ⇒ Object
-
#initialize(file) ⇒ ConfigStore
constructor
A new instance of ConfigStore.
- #load ⇒ Object
- #save ⇒ Object
- #update(c = {}) ⇒ Object
Constructor Details
#initialize(file) ⇒ ConfigStore
Returns a new instance of ConfigStore.
7 8 9 |
# File 'lib/teambox-things-sync/config_store.rb', line 7 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/teambox-things-sync/config_store.rb', line 5 def file @file end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 |
# File 'lib/teambox-things-sync/config_store.rb', line 16 def [](key) load @config[key] end |
#[]=(key, value) ⇒ Object
21 22 23 |
# File 'lib/teambox-things-sync/config_store.rb', line 21 def []=(key, value) @config[key] = value end |
#delete(*keys) ⇒ Object
25 26 27 28 29 |
# File 'lib/teambox-things-sync/config_store.rb', line 25 def delete(*keys) keys.each { |key| @config.delete(key) } save self end |
#load ⇒ Object
11 12 13 14 |
# File 'lib/teambox-things-sync/config_store.rb', line 11 def load @config ||= YAML::load(open(file)) self end |
#save ⇒ Object
37 38 39 40 |
# File 'lib/teambox-things-sync/config_store.rb', line 37 def save File.open(file, 'w') { |f| f.write(YAML.dump(@config)) } self end |
#update(c = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/teambox-things-sync/config_store.rb', line 31 def update(c={}) @config.merge!(c) save self end |