Sha256: 758f0c65175b9cc726353ff4f5be191e078866d5bd03be4998764e77fc74bfc9

Contents?: true

Size: 809 Bytes

Versions: 1

Compression:

Stored size: 809 Bytes

Contents

module Heirloom
  class Extracter

    include Heirloom::Misc::Tmp

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

    def extract(args)
      @tmp_archive = random_archive

      create_tmp_archive args[:archive]
      extract_tmp_archive args[:output]
      delete_tmp_archive
    end

    private

    def create_tmp_archive(archive)
      File.open(@tmp_archive, 'w') { |local_file| local_file.write archive }
    end

    def extract_tmp_archive(output)
      @logger.info "Extracting archive to '#{output}'."
      cmd = "tar xzf #{@tmp_archive} -C #{output}"
      @logger.debug "Executing '#{cmd}'."
      `#{cmd}`
    end
  
    def delete_tmp_archive
      @logger.debug "Deleting '#{@tmp_archive}'."
      File.delete @tmp_archive
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heirloom-0.5.0rc2 lib/heirloom/archive/extracter.rb