Class: Dandelion::Adapter::S3
- Inherits:
-
Base
- Object
- Base
- Dandelion::Adapter::S3
show all
- Defined in:
- lib/dandelion/adapter/s3.rb
Instance Method Summary
collapse
Methods inherited from Base
adapter, create_adapter, requires_gems
Constructor Details
#initialize(config) ⇒ S3
Returns a new instance of S3.
7
8
9
10
11
12
|
# File 'lib/dandelion/adapter/s3.rb', line 7
def initialize(config)
require 'aws/s3'
@config = config
@config.defaults(preserve_permissions: true)
end
|
Instance Method Details
#delete(file) ⇒ Object
39
40
41
42
|
# File 'lib/dandelion/adapter/s3.rb', line 39
def delete(file)
connect!
AWS::S3::S3Object.delete(path(file), bucket_name)
end
|
#read(file) ⇒ Object
14
15
16
17
18
|
# File 'lib/dandelion/adapter/s3.rb', line 14
def read(file)
connect!
return nil unless AWS::S3::S3Object.exists?(path(file), bucket_name)
AWS::S3::S3Object.value(path(file), bucket_name)
end
|
#to_s ⇒ Object
44
45
46
|
# File 'lib/dandelion/adapter/s3.rb', line 44
def to_s
"s3://#{@config[:access_key_id]}@#{bucket_name}/#{@config[:path]}"
end
|
#write(file, data) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/dandelion/adapter/s3.rb', line 20
def write(file, data)
connect!
key = path(file)
begin
policy = AWS::S3::S3Object.acl(key, bucket_name) if @config[:preserve_permissions]
rescue AWS::S3::NoSuchKey
end
options = {}
options[:cache_control] = "max-age=#{@config[:cache_control]}" if @config[:cache_control]
options[:expires] = @config[:expires] if @config[:expires]
AWS::S3::S3Object.store(path(file), data, bucket_name, options)
AWS::S3::S3Object.acl(key, bucket_name, policy) unless policy.nil?
end
|