Class: Canfig::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/canfig/yaml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/canfig/yaml.rb', line 3

def file
  @file
end

Instance Method Details

#loadObject Also known as: data



9
10
11
# File 'lib/canfig/yaml.rb', line 9

def load
  @data ||= ::YAML.load_file(file).symbolize_keys
end

#reloadObject



14
15
16
17
# File 'lib/canfig/yaml.rb', line 14

def reload
  @data = nil
  self.load
end

#writeObject



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