Class: YAMLObjectMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/less_active_record/yaml_object_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ YAMLObjectMapper

Returns a new instance of YAMLObjectMapper.



4
5
6
# File 'lib/less_active_record/yaml_object_mapper.rb', line 4

def initialize(file_name)
  @file_name = file_name
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



2
3
4
# File 'lib/less_active_record/yaml_object_mapper.rb', line 2

def file_name
  @file_name
end

Instance Method Details

#dump_file(object) ⇒ Object



12
13
14
15
16
# File 'lib/less_active_record/yaml_object_mapper.rb', line 12

def dump_file(object)
  File.open(file_name, 'w') do |file|
    YAML.dump(object, file)
  end
end

#load_fileObject



8
9
10
# File 'lib/less_active_record/yaml_object_mapper.rb', line 8

def load_file
  YAML.load_file(file_name) if File.exists?(file_name)
end