Class: SCV::Config
- Inherits:
-
Object
- Object
- SCV::Config
- Defined in:
- lib/scv/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(file_store, file_name) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(file_store, file_name) ⇒ Config
7 8 9 10 11 12 13 |
# File 'lib/scv/config.rb', line 7 def initialize(file_store, file_name) @file_store = file_store @file_name = file_name @data = {} load end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/scv/config.rb', line 5 def data @data end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 |
# File 'lib/scv/config.rb', line 23 def [](key) hash, key = resolve_key key hash[key] end |
#[]=(key, value) ⇒ Object
28 29 30 31 |
# File 'lib/scv/config.rb', line 28 def []=(key, value) hash, key = resolve_key key, create: true hash[key] = value end |
#delete(key) ⇒ Object
33 34 35 36 |
# File 'lib/scv/config.rb', line 33 def delete(key) hash, key = resolve_key key, create: false hash.delete key end |
#load ⇒ Object
15 16 17 |
# File 'lib/scv/config.rb', line 15 def load @data = YAML.load @file_store.fetch(@file_name) if @file_store.file? @file_name end |
#save ⇒ Object
19 20 21 |
# File 'lib/scv/config.rb', line 19 def save @file_store.store @file_name, @data.to_yaml end |