Class: MidwireCommon::YamlSetting
- Inherits:
-
Object
- Object
- MidwireCommon::YamlSetting
- Defined in:
- lib/midwire_common/yaml_setting.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #data ⇒ 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.
8 9 10 |
# File 'lib/midwire_common/yaml_setting.rb', line 8 def initialize(file) @file = file end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/midwire_common/yaml_setting.rb', line 6 def config @config end |
#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
22 23 24 25 |
# File 'lib/midwire_common/yaml_setting.rb', line 22 def [](key) load config[key] end |
#[]=(key, value) ⇒ Object
27 28 29 30 |
# File 'lib/midwire_common/yaml_setting.rb', line 27 def []=(key, value) load config[key] = value end |
#data ⇒ Object
32 33 34 35 |
# File 'lib/midwire_common/yaml_setting.rb', line 32 def data load config end |
#load ⇒ Object
12 13 14 15 |
# File 'lib/midwire_common/yaml_setting.rb', line 12 def load @config ||= YAML.load_file(file) || {} self end |
#save ⇒ Object
17 18 19 20 |
# File 'lib/midwire_common/yaml_setting.rb', line 17 def save File.open(file, 'w') { |f| f.write(YAML.dump(config)) } self end |