Class: Fclay::RemoteStorage::S3
- Inherits:
-
Base
- Object
- Base
- Fclay::RemoteStorage::S3
show all
- Defined in:
- lib/fclay/remote_storage/s3.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #options, #storage, #uploading_object
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#get_storage_by_name
Constructor Details
#initialize(name, uploading_object) ⇒ S3
Returns a new instance of S3.
5
6
7
8
9
|
# File 'lib/fclay/remote_storage/s3.rb', line 5
def initialize(name, uploading_object)
super
@bucket = Aws::S3::Resource.new.bucket(bucket_name)
end
|
Class Method Details
.url(name = nil) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/fclay/remote_storage/s3.rb', line 34
def self.url(name = nil)
return '' unless name
storage = Fclay.configuration.remote_storages[name]
if (storage[:cloudfront].present?)
"https://#{storage[:cloudfront]}.cloudfront.net"
else
"https://#{storage[:bucket]}.s3.amazonaws.com"
end
end
|
Instance Method Details
#bucket_name ⇒ Object
48
49
50
|
# File 'lib/fclay/remote_storage/s3.rb', line 48
def bucket_name
Fclay.configuration.remote_storages[name][:bucket]
end
|
#bucket_object(style = nil) ⇒ Object
30
31
32
|
# File 'lib/fclay/remote_storage/s3.rb', line 30
def bucket_object(style = nil)
@bucket.object(uploading_object.remote_file_path(style))
end
|
#content_type ⇒ Object
44
45
46
|
# File 'lib/fclay/remote_storage/s3.rb', line 44
def content_type
uploading_object.try(:content_type)
end
|
#delete_files ⇒ Object
24
25
26
27
28
|
# File 'lib/fclay/remote_storage/s3.rb', line 24
def delete_files
(@options[:styles].try(:keys) || [nil]).each do |style|
bucket_object(style).delete
end
end
|
#upload(options = {}) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/fclay/remote_storage/s3.rb', line 11
def upload(options = {})
(@options[:styles].try(:keys) || [nil]).each do |style|
obj = bucket_object(style)
obj.put({
body: File.read(uploading_object.local_file_path(style)),
acl: "public-read",
content_type: content_type
})
end
super unless options[:without_update]
end
|