Class: Codebreaker::YamlMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/utils/yaml_mapper.rb

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Object



14
15
16
# File 'lib/codebreaker/utils/yaml_mapper.rb', line 14

def load(path)
  File.file?(path) ? Psych.load(File.read(path)) : []
end

.save(object, path) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/codebreaker/utils/yaml_mapper.rb', line 6

def save(object, path)
  stats = load(path)
  stats << object
  File.open(path, 'w') do |file|
    file.write(stats.to_yaml)
  end
end