Class: OpsPreflight::S3Transfer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, file) ⇒ S3Transfer

Returns a new instance of S3Transfer.



6
7
8
9
# File 'lib/ops_preflight/s3_transfer.rb', line 6

def initialize(bucket, file)
  @bucket = bucket
  @file = file
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



3
4
5
# File 'lib/ops_preflight/s3_transfer.rb', line 3

def bucket
  @bucket
end

#fileObject

Returns the value of attribute file.



4
5
6
# File 'lib/ops_preflight/s3_transfer.rb', line 4

def file
  @file
end

Instance Method Details

#downloadObject



24
25
26
27
28
29
30
31
# File 'lib/ops_preflight/s3_transfer.rb', line 24

def download
  basename = File.basename(file)

  remote_file = directory.files.get(basename)
  File.open(file, 'w') do |local_file|
    local_file.write(remote_file.body)
  end
end

#uploadObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ops_preflight/s3_transfer.rb', line 11

def upload
  basename = File.basename(file)

  remote_file = directory.files.head(basename)
  remote_file.destroy if remote_file

  directory.files.create(
    :key => basename,
    :body => File.open(file),
    :public => false
  )
end