Sha256: 4d6902b04be8db2f008da95c4d58d4d48a7e70cd183324cdaa2dbff26a0c3fc4

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Heirloom

  class Downloader

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

    def download(args)
      region = args[:region]
      base_prefix = args[:base_prefix]

      s3_downloader = Downloader::S3.new :config => @config,
                                         :logger => @logger,
                                         :region => region

      bucket = get_bucket :region => region, :base_prefix => base_prefix

      @logger.info "Downloading s3://#{bucket}/#{key} from #{region}."

      file = s3_downloader.download_file :bucket => bucket,
                                         :key    => key

      output = args[:output] ||= "./#{key.split('/').last}"

      @logger.info "Writing file to #{output}."

      File.open(output, 'w') do |local_file|
        local_file.write file
      end

      @logger.info "Download complete."
    end

    private

    def get_bucket(args)
      "#{args[:base_prefix]}-#{args[:region]}"
    end

    def key
      "#{@name}/#{@id}.tar.gz"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
heirloom-0.5.0rc1 lib/heirloom/archive/downloader.rb
heirloom-0.4.1rc1 lib/heirloom/archive/downloader.rb