Sha256: e259f060026b7696f86d2980ef8df72904e6b617b0291159ce2dfa94c821f12a

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

module Backup
  class Archive
    include Backup::CLI

    ##
    # Stores the name of the archive
    attr_accessor :name

    ##
    # Stores an array of different paths/files to store
    attr_accessor :paths

    ##
    # Stores the path to the archive directory
    attr_accessor :archive_path

    ##
    # Takes the name of the archive and the configuration block
    def initialize(name, &block)
      @name         = name.to_sym
      @paths        = Array.new
      @archive_path = File.join(TMP_PATH, TRIGGER, 'archive')

      instance_eval(&block)
    end

    ##
    # Adds new paths to the @paths instance variable array
    def add(path)
      @paths << path
    end

    ##
    # Archives all the provided paths in to a single .tar file
    # and places that .tar file in the folder which later will be packaged
    def perform!
      mkdir(archive_path)
      Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
      run("#{ utility(:tar) } -c #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
    end

  private

    ##
    # Returns a "tar-ready" string of all the specified paths combined
    def paths_to_package
      paths.map do |path|
        "'#{path}'"
      end.join("\s")
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
backup-3.0.4 lib/backup/archive.rb
backup-3.0.3 lib/backup/archive.rb
backup-3.0.2.build.0 lib/backup/archive.rb
backup-3.0.2 lib/backup/archive.rb
backup-3.0.1.build.0 lib/backup/archive.rb
backup-3.0.1 lib/backup/archive.rb
backup-3.0.0.build.0 lib/backup/archive.rb
backup-3.0.0 lib/backup/archive.rb