Class: Rstreet::BucketCommunicator

Inherits:
Object
  • Object
show all
Defined in:
lib/bucket_communicator.rb

Instance Method Summary collapse

Constructor Details

#initialize(s3_bucket, dry_run) ⇒ BucketCommunicator

Returns a new instance of BucketCommunicator.



7
8
9
# File 'lib/bucket_communicator.rb', line 7

def initialize(s3_bucket, dry_run)
  @s3, @dry_run = S3.new(s3_bucket), dry_run
end

Instance Method Details

#pull_manifest(manifest_uploadable) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/bucket_communicator.rb', line 11

def pull_manifest(manifest_uploadable)
  manifest_file = @s3.get_file(manifest_uploadable)
  if manifest_file
    ManifestBuilder.new(manifest_file).read
  else
    ManifestBuilder.empty_manifest
  end
end

#upload(uploadables) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bucket_communicator.rb', line 20

def upload(uploadables)
  # TODO: refactor into sep procs
  uploadables.map do |u|
    if dry_run?
      puts "dry run upload: #{u.name}"
    else
      begin
        @s3.put_file(u)
        puts "uploaded:        #{u.name}"
      rescue StandardError => e
        puts "error uploading: #{u.name}", e
      end
    end
  end
end