Class: YamlRecord::Adapters::LocalStore

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/yaml_record.rb

Instance Method Summary collapse

Instance Method Details

#read(source) ⇒ Object

Returns YAML File as ruby collection

Example:

@adapter.read("foo") => [{...}, {...}]


19
20
21
22
23
# File 'lib/ruby_home/yaml_record.rb', line 19

def read(source)
  return false unless File.exists?(source)

  YAML.load_file(source)
end

#write(source, collection) ⇒ Object

Writes ruby collection as YAML File

Example:

@adapter.write("foo", [{...}, {...}]) => "<yaml data>"


31
32
33
# File 'lib/ruby_home/yaml_record.rb', line 31

def write(source, collection)
  File.open(source, 'w') {|f| f.write(collection.to_yaml) }
end