Sha256: 77106f1f3db1400ae009103f3596f26c06c78413fcdd54e85ada3ab50c472536

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'tempfile'

module Heirloom

  class Directory

    attr_reader :local_build

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

    def build_artifact_from_directory(args)
      @secret = args[:secret]

      @local_build = Tempfile.new('archive.tar.gz').path

      @logger.debug "Building Heirloom '#{@local_build}' from '#{@path}'."
      @logger.debug "Excluding #{@exclude.to_s}."
      @logger.debug "Adding #{files_to_pack}."

      return build_archive unless @secret

      build_encrypted_archive 
    end

    private

    def build_archive
      command = "cd #{@path} && tar czf #{@local_build} #{files_to_pack}"
      @logger.info "Archiving with: `#{command}`"
      output = `#{command}`
      @logger.debug "Exited with status: '#{$?.exitstatus}' ouput: '#{output}'"
      $?.success?
    end

    def build_encrypted_archive
      return false unless build_archive
      @logger.info "Secret provided. Encrypting."
      @local_build = cipher_file.encrypt_file :file   => @local_build,
                                              :secret => @secret
    end

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

    def cipher_file
      @cipher_file = Heirloom::Cipher::File.new :config => @config
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
heirloom-0.7.1 lib/heirloom/directory/directory.rb
heirloom-0.7.0 lib/heirloom/directory/directory.rb
heirloom-0.7.0rc1 lib/heirloom/directory/directory.rb