Class: YAMLObjectMapper
- Inherits:
-
Object
- Object
- YAMLObjectMapper
- Defined in:
- lib/less_active_record/yaml_object_mapper.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
- #dump_file(object) ⇒ Object
-
#initialize(file_name) ⇒ YAMLObjectMapper
constructor
A new instance of YAMLObjectMapper.
- #load_file ⇒ Object
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_name ⇒ Object (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_file ⇒ Object
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 |