Class: MidwireCommon::YamlSetting
- Inherits:
-
Object
- Object
- MidwireCommon::YamlSetting
- Defined in:
- lib/midwire_common/yaml_setting.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(file) ⇒ YamlSetting
constructor
A new instance of YamlSetting.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(file) ⇒ YamlSetting
Returns a new instance of YamlSetting.
7 8 9 |
# File 'lib/midwire_common/yaml_setting.rb', line 7 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/midwire_common/yaml_setting.rb', line 5 def file @file end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 24 |
# File 'lib/midwire_common/yaml_setting.rb', line 21 def [](key) load @config[key] end |
#[]=(key, value) ⇒ Object
26 27 28 29 |
# File 'lib/midwire_common/yaml_setting.rb', line 26 def []=(key, value) load @config[key] = value end |
#load ⇒ Object
11 12 13 14 |
# File 'lib/midwire_common/yaml_setting.rb', line 11 def load @config ||= YAML.load_file(file) || {} self end |
#save ⇒ Object
16 17 18 19 |
# File 'lib/midwire_common/yaml_setting.rb', line 16 def save File.open(file, 'w') { |f| f.write(YAML.dump(@config)) } self end |