Sha256: 1a9c39a479cca1fd74482126bbd3cb9846862323e7a3f9e116505a4b669dd367

Contents?: true

Size: 1.22 KB

Versions: 24

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

module Backup
  module Storage
    class Object

      ##
      # Holds the type attribute
      attr_accessor :storage_file

      ##
      # Instantiates a new Backup::Storage::Object and stores the
      # full path to the storage file (yaml) in the @storage_file attribute
      def initialize(type)
        @storage_file = File.join(DATA_PATH, TRIGGER, "#{type}.yml")
      end

      ##
      # 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[0]
      # and the oldest in Backup::Storage::Object.load[-1]
      def load
        if File.exist?(storage_file)
          YAML.load_file(storage_file).sort { |a,b| b.time <=> a.time }
        else
          []
        end
      end

      ##
      # Takes the provided objects and converts it to YAML format.
      # The YAML data gets written to the storage file
      def write(objects)
        File.open(storage_file, 'w') do |file|
          file.write(objects.to_yaml)
        end
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
backup-3.0.19 lib/backup/storage/object.rb
backup-3.0.18 lib/backup/storage/object.rb
interu-backup-3.0.16 lib/backup/storage/object.rb
backup-3.0.16 lib/backup/storage/object.rb
backup-3.0.15 lib/backup/storage/object.rb
backup-3.0.14 lib/backup/storage/object.rb
backup-3.0.13 lib/backup/storage/object.rb
backup-3.0.12 lib/backup/storage/object.rb
backup-3.0.11 lib/backup/storage/object.rb
alg-backup-3.0.10 lib/backup/storage/object.rb
backup-3.0.10 lib/backup/storage/object.rb
backup-3.0.9 lib/backup/storage/object.rb
backup-3.0.8 lib/backup/storage/object.rb
backup-3.0.7 lib/backup/storage/object.rb
backup-3.0.6 lib/backup/storage/object.rb
backup-3.0.5 lib/backup/storage/object.rb
backup-3.0.4 lib/backup/storage/object.rb
backup-3.0.3 lib/backup/storage/object.rb
backup-3.0.2.build.0 lib/backup/storage/object.rb
backup-3.0.2 lib/backup/storage/object.rb