Sha256: e3a129c23440245837891fcd9afa57a76e95c4e8c166f62e3c1af0d391e4bbe1

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

require 'zlib'
require 'archive/tar/minitar'
require 'tmpdir'

include Archive::Tar

module Heirloom

  class Directory

    attr_accessor :config, :exclude, :local_build, :path, :logger

    def initialize(args)
      self.config = args[:config]
      self.exclude = args[:exclude]
      self.path = args[:path]
      self.logger = config.logger
    end

    def build_artifact_from_directory
      random_text = (0...8).map{65.+(rand(25)).chr}.join

      unless local_build
        self.local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
      end

      logger.info "Building artifact '#{local_build}' from '#{path}'."
      logger.info "Excluding #{exclude.to_s}."
      logger.info "Adding #{files_to_pack.to_s}."

      tgz = Zlib::GzipWriter.new File.open(local_build, 'wb')

      Minitar.pack(files_to_pack, tgz)
    end

    private
      
    def files_to_pack
      Dir.entries(path) - ['.', '..'] - exclude
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heirloom-0.1.4 lib/heirloom/directory/directory.rb