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



6
7
8
# File 'lib/less_active_record/yaml_object_mapper.rb', line 6

def initialize(file_name)
  @file_name = file_name
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



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

def file_name
  @file_name
end

Instance Method Details

#dump_file(object) ⇒ Object



14
15
16
17
18
# File 'lib/less_active_record/yaml_object_mapper.rb', line 14

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

#load_fileObject



10
11
12
# File 'lib/less_active_record/yaml_object_mapper.rb', line 10

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