Class: Backup::Storage::Object
- Inherits:
-
Object
- Object
- Backup::Storage::Object
- Defined in:
- lib/backup/storage/object.rb
Instance Attribute Summary collapse
-
#storage_file ⇒ Object
Holds the type attribute.
Instance Method Summary collapse
-
#initialize(type) ⇒ Object
constructor
Instantiates a new Backup::Storage::Object and stores the full path to the storage file (yaml) in the @storage_file attribute.
-
#load ⇒ Object
Tries to load an existing YAML file and returns an array of storage objects.
-
#write(objects) ⇒ Object
Takes the provided objects and converts it to YAML format.
Constructor Details
Instance Attribute Details
#storage_file ⇒ Object
Holds the type attribute
9 10 11 |
# File 'lib/backup/storage/object.rb', line 9 def storage_file @storage_file end |
Instance Method Details
#load ⇒ Object
Tries to load an existing YAML file and returns an array of storage objects. If no file exists, an empty array gets returned
If a file is loaded it’ll sort the array of objects by @time descending. The newest backup storage object comes in Backup::Storage::Object.load and the oldest in Backup::Storage::Object.load
26 27 28 29 30 31 32 |
# File 'lib/backup/storage/object.rb', line 26 def load if File.exist?(storage_file) YAML.load_file(storage_file).sort { |a,b| b.time <=> a.time } else [] end end |
#write(objects) ⇒ Object
Takes the provided objects and converts it to YAML format. The YAML data gets written to the storage file
37 38 39 40 41 |
# File 'lib/backup/storage/object.rb', line 37 def write(objects) File.open(storage_file, 'w') do |file| file.write(objects.to_yaml) end end |