Class: Attachs::Storages::S3
Instance Method Summary collapse
- #copy(current_path, new_path) ⇒ Object
- #delete(path) ⇒ Object
- #exists?(path) ⇒ Boolean
- #find_each ⇒ Object
- #get(path) ⇒ Object
- #move(current_path, new_path) ⇒ Object
- #process(file, paths, options) ⇒ Object
- #url(path) ⇒ Object
Instance Method Details
#copy(current_path, new_path) ⇒ Object
38 39 40 41 |
# File 'lib/attachs/storages/s3.rb', line 38 def copy(current_path, new_path) Rails.logger.info "Copying: #{current_path} => #{new_path}" bucket.object(current_path).copy_to bucket.object(new_path), acl: 'public-read' end |
#delete(path) ⇒ Object
48 49 50 51 |
# File 'lib/attachs/storages/s3.rb', line 48 def delete(path) Rails.logger.info "Deleting: #{path}" bucket.object(path).delete end |
#exists?(path) ⇒ Boolean
53 54 55 |
# File 'lib/attachs/storages/s3.rb', line 53 def exists?(path) bucket.object(path).exists? end |
#find_each ⇒ Object
57 58 59 60 61 |
# File 'lib/attachs/storages/s3.rb', line 57 def find_each bucket.objects.each do |object| yield object.key end end |
#get(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/attachs/storages/s3.rb', line 27 def get(path) file = build_tempfile(path) file.binmode bucket.object(path).get do |chunk| file.write chunk end file.rewind file.close file end |
#move(current_path, new_path) ⇒ Object
43 44 45 46 |
# File 'lib/attachs/storages/s3.rb', line 43 def move(current_path, new_path) Rails.logger.info "Moving: #{current_path} => #{new_path}" bucket.object(current_path).move_to bucket.object(new_path) end |
#process(file, paths, options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/attachs/storages/s3.rb', line 14 def process(file, paths, ) if processable?(file.path) processor = build_processor(file.path) paths.each do |style, path| tmp = build_tempfile(path) processor.process tmp.path, [style] upload tmp.path, path end else upload file.path, paths[:original] end end |
#url(path) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/attachs/storages/s3.rb', line 5 def url(path) base_url = Attachs.configuration.base_url if base_url.present? Pathname.new(base_url).join(path).to_s else bucket.object(path).public_url end end |