Sha256: c742862ace960c6334cbaa148e8687aa65ded9f909463abaac2d84f1b1cb3e14

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

require 'tempfile'

module Heirloom
  class Writer

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

    def save_archive(args)
      @output  = args[:output]
      @file    = args[:file]
      @archive = args[:archive]
      @extract = args[:extract]

      @extract ? extract_archive : write_archive
    end

    private

    def extract_archive
      @tmp_archive = Tempfile.new('archive.tar.gz').path

      create_tmp_archive 
      extract_tmp_archive
    end

    def write_archive
      output_file = File.join @output, @file
      @logger.info "Writing Heirloom to '#{output_file}'."
      File.open(output_file, 'w') { |local_file| local_file.write @archive }
    end

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

    def extract_tmp_archive
      @logger.info "Extracting Heirloom to '#{@output}'."
      cmd = "tar xzf #{@tmp_archive} -C #{@output}"
      @logger.debug "Executing '#{cmd}'."
      `#{cmd}`
      if $?.success?
        @logger.debug "Heirloom succesfully extracted."
        true
      else
        @logger.error "Error extracting Heirloom."
        false
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
heirloom-0.12.7 lib/heirloom/archive/writer.rb
heirloom-0.12.5 lib/heirloom/archive/writer.rb
heirloom-0.12.4 lib/heirloom/archive/writer.rb
heirloom-0.12.3 lib/heirloom/archive/writer.rb
heirloom-0.12.2 lib/heirloom/archive/writer.rb
heirloom-0.12.1 lib/heirloom/archive/writer.rb
heirloom-0.12.0 lib/heirloom/archive/writer.rb
heirloom-0.11.2 lib/heirloom/archive/writer.rb
heirloom-0.11.1 lib/heirloom/archive/writer.rb
heirloom-0.11.0 lib/heirloom/archive/writer.rb
heirloom-0.11.0.beta.2 lib/heirloom/archive/writer.rb
heirloom-0.11.0.beta.1 lib/heirloom/archive/writer.rb
heirloom-0.10.1 lib/heirloom/archive/writer.rb
heirloom-0.10.0 lib/heirloom/archive/writer.rb