Sha256: 483065bcf316904c24ab4154da3e5a610e698b8ca6824d9c82e67516f7541bf5

Contents?: true

Size: 1.18 KB

Versions: 14

Compression:

Stored size: 1.18 KB

Contents

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 archive 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 archive to '#{@output}'."
      cmd = "tar xzf #{@tmp_archive} -C #{@output}"
      @logger.debug "Executing '#{cmd}'."
      `#{cmd}`
      if $?.success?
        @logger.debug "Archive succesfully extracted."
        true
      else
        @logger.error "Error extracting archive."
        false
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
heirloom-0.7.4 lib/heirloom/archive/writer.rb
heirloom-0.7.3 lib/heirloom/archive/writer.rb
heirloom-0.7.3rc2 lib/heirloom/archive/writer.rb
heirloom-0.7.3rc1 lib/heirloom/archive/writer.rb
heirloom-0.7.2 lib/heirloom/archive/writer.rb
heirloom-0.7.2rc2 lib/heirloom/archive/writer.rb
heirloom-0.7.2rc1 lib/heirloom/archive/writer.rb
heirloom-0.7.1 lib/heirloom/archive/writer.rb
heirloom-0.7.0 lib/heirloom/archive/writer.rb
heirloom-0.7.0rc1 lib/heirloom/archive/writer.rb
heirloom-0.6.1 lib/heirloom/archive/writer.rb
heirloom-0.6.0rc1 lib/heirloom/archive/writer.rb
heirloom-0.5.0rc4 lib/heirloom/archive/writer.rb
heirloom-0.5.0rc3 lib/heirloom/archive/writer.rb