class Requeus::Adapter::S3

Public Class Methods

new(options) click to toggle source
Calls superclass method Requeus::Adapter::Filesystem::new
# File lib/requeus/adapter/s3.rb, line 6
def initialize options
  @options = options
  super 'path' => options['cache_path']
end

Public Instance Methods

delete(uid) click to toggle source
Calls superclass method Requeus::Adapter::Filesystem#delete
# File lib/requeus/adapter/s3.rb, line 21
def delete uid
  bucket.delete_key uid
  super uid
end
get(uid) click to toggle source
Calls superclass method Requeus::Adapter::Filesystem#get
# File lib/requeus/adapter/s3.rb, line 26
def get uid
  key = bucket.key(uid)
  raise "S3:File 's3://#{bucket.name}/#{uid}' doesn't exists" unless key.exists?
  File.open(path_for(uid), 'w') {|f| f.write(key.data) }
  super uid
end
put(file) click to toggle source
# File lib/requeus/adapter/s3.rb, line 11
def put file
  uid = generate_id
  begin
    bucket.put(uid, open(file.path))
  rescue Aws::AwsError
    raise "S3:Failed to upload local file '#{file}' as '#{uid}' to AWS/S3 bucket '#{bucket.name}'"
  end
  uid
end

Private Instance Methods

bucket() click to toggle source
# File lib/requeus/adapter/s3.rb, line 39
def bucket
  @bucket ||= begin
    bucket = connection.bucket(@options['bucket'])
    bucket = connection.bucket(@options['bucket'], true) unless bucket.exists? #todo: permissions
    bucket
  end
end
connection() click to toggle source
# File lib/requeus/adapter/s3.rb, line 35
def connection
  @connection ||= Aws::S3.new(@options['access_key_id'], @options['secret_access_key'])
end