Class: MidwireCommon::YamlSetting
- Inherits:
-
Object
- Object
- MidwireCommon::YamlSetting
- Defined in:
- lib/midwire_common/yaml_setting.rb
Overview
Simple class for YAML settings
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file ⇒ Object
readonly
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.
10 11 12 |
# File 'lib/midwire_common/yaml_setting.rb', line 10 def initialize(file) @file = file end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/midwire_common/yaml_setting.rb', line 8 def config @config end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/midwire_common/yaml_setting.rb', line 8 def file @file end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 27 |
# File 'lib/midwire_common/yaml_setting.rb', line 24 def [](key) load config[key] end |
#[]=(key, value) ⇒ Object
29 30 31 32 |
# File 'lib/midwire_common/yaml_setting.rb', line 29 def []=(key, value) load config[key] = value end |
#data ⇒ Object
34 35 36 37 |
# File 'lib/midwire_common/yaml_setting.rb', line 34 def data load config end |
#load ⇒ Object
14 15 16 17 |
# File 'lib/midwire_common/yaml_setting.rb', line 14 def load @config ||= YAML.load_file(file) || {} self end |
#save ⇒ Object
19 20 21 22 |
# File 'lib/midwire_common/yaml_setting.rb', line 19 def save File.write(file, YAML.dump(config)) self end |