Class: Requeus::Adapter::S3

Inherits:
Filesystem show all
Defined in:
lib/requeus/adapter/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ S3

Returns a new instance of S3.



6
7
8
9
# File 'lib/requeus/adapter/s3.rb', line 6

def initialize options
  @options = options
  super 'path' => options['cache_path']
end

Instance Method Details

#delete(uid) ⇒ Object



21
22
23
24
# File 'lib/requeus/adapter/s3.rb', line 21

def delete uid
  bucket.delete_key uid
  super uid
end

#get(uid) ⇒ Object



26
27
28
29
30
31
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
# 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