Class: Canfig::YAML
- Inherits:
-
Object
- Object
- Canfig::YAML
- Defined in:
- lib/canfig/yaml.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file) ⇒ YAML
constructor
A new instance of YAML.
- #load ⇒ Object (also: #data)
- #reload ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(file) ⇒ YAML
Returns a new instance of YAML.
5 6 7 |
# File 'lib/canfig/yaml.rb', line 5 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/canfig/yaml.rb', line 3 def file @file end |
Instance Method Details
#load ⇒ Object Also known as: data
9 10 11 |
# File 'lib/canfig/yaml.rb', line 9 def load @data ||= ::YAML.load_file(file).symbolize_keys end |
#reload ⇒ Object
14 15 16 17 |
# File 'lib/canfig/yaml.rb', line 14 def reload @data = nil self.load end |
#write ⇒ Object
19 20 21 22 23 |
# File 'lib/canfig/yaml.rb', line 19 def write File.open(file, 'w') do |f| f.write(::YAML.dump(data)) end end |