class RSpec::Storage::S3::Uploader

Public Class Methods

new(s3_client, uri) click to toggle source
# File lib/rspec/storage/s3.rb, line 23
def initialize(s3_client, uri)
  @tempfile = Tempfile.new("rspec-storage-s3")
  @s3_client = s3_client
  @uri = uri
  @bucket = uri.host
  @key = uri.path[1..-1]
end

Public Instance Methods

__getobj__() click to toggle source
# File lib/rspec/storage/s3.rb, line 31
def __getobj__
  @tempfile
end
close() click to toggle source
# File lib/rspec/storage/s3.rb, line 35
def close
  @tempfile.flush
  @tempfile.rewind
  @s3_client.put_object(bucket: @bucket, key: @key, body: @tempfile)
  @s3_client.wait_until(:object_exists, bucket: @bucket, key: @key) do |w|
    w.max_attempts = 5
  end
  $stdout.puts "Upload to #{@uri.to_s}"
ensure
  @tempfile.close
end