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
38
39
40
41
42
43
44
45
46
|
# File 'lib/fclay/remote_storage/s3.rb', line 38
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
52
53
54
|
# File 'lib/fclay/remote_storage/s3.rb', line 52
def bucket_name
Fclay.configuration.remote_storages[name][:bucket]
end
|
#bucket_object(style = nil) ⇒ Object
34
35
36
|
# File 'lib/fclay/remote_storage/s3.rb', line 34
def bucket_object(style = nil)
@bucket.object(uploading_object.remote_file_path(style))
end
|
#content_type ⇒ Object
48
49
50
|
# File 'lib/fclay/remote_storage/s3.rb', line 48
def content_type
uploading_object.try(:content_type)
end
|
#delete_files ⇒ Object
28
29
30
31
32
|
# File 'lib/fclay/remote_storage/s3.rb', line 28
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
23
24
25
26
|
# File 'lib/fclay/remote_storage/s3.rb', line 11
def upload(options = {})
(@options[:styles].try(:keys) || [nil]).each do |style|
begin
obj = bucket_object(style)
obj.put({
body: File.read(uploading_object.local_file_path(style)),
acl: "public-read",
content_type: content_type
})
rescue => e
Rails.logger.debug(e.message)
end
end
super unless options[:without_update]
end
|