class RainbowStorage::Adapters::S3::Adapter

Attributes

bucket[RW]

Public Instance Methods

delete(path) click to toggle source
# File lib/rainbow_storage/adapters/s3/adapter.rb, line 26
def delete(path)
  object = bucket.objects.find(path)
  object.destroy
end
get(path) click to toggle source

TODO: should we deal with tempfiles here? or just return a data?

# File lib/rainbow_storage/adapters/s3/adapter.rb, line 11
def get(path)
  object = bucket.objects.find(path)
  tempfile = Tempfile.new
  tempfile.write(object.content)
  tempfile.rewind
  tempfile
end
public_url(path) click to toggle source
# File lib/rainbow_storage/adapters/s3/adapter.rb, line 31
def public_url(path)
  object = bucket.objects.find(path)
  object.temporary_url(Time.now + 1800)
end
put(path, data) click to toggle source
# File lib/rainbow_storage/adapters/s3/adapter.rb, line 19
def put(path, data)
  new_object = bucket.objects.build(path)
  new_object.content = data
  new_object.acl = :public_read
  new_object.save
end

Private Instance Methods

post_initialize() click to toggle source
# File lib/rainbow_storage/adapters/s3/adapter.rb, line 38
def post_initialize
  @service = ::S3::Service.new(access_key_id: config[:access_key],
                             secret_access_key: config[:secret_key])
  @bucket = @service.bucket(config[:bucket])
end