Sha256: a9dfd4b0dd095f3054c54a8fddc01e64868d704baf9931678cb3ce6c3540809b

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Heirloom

  class Downloader

    attr_accessor :config, :id, :name, :logger

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

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

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

      bucket = reader.get_bucket :region => region
      key = reader.get_key :region => region

      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 reader
      @reader ||= Reader.new :config => config,
                             :name   => name,
                             :id     => id
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
heirloom-0.3.1 lib/heirloom/archive/downloader.rb
heirloom-0.3.0 lib/heirloom/archive/downloader.rb
heirloom-0.3.0.rc1 lib/heirloom/archive/downloader.rb
heirloom-0.2.0 lib/heirloom/archive/downloader.rb