class FileManager::S3

Public Class Methods

delete(file_path:, bucket:) click to toggle source
# File lib/file_manager/s3.rb, line 10
def delete(file_path:, bucket:)
  new(file_path: file_path, bucket: bucket).delete
end
new(options = {}) click to toggle source
# File lib/file_manager/s3.rb, line 25
def initialize(options = {})
  # Mandatory options
  @file_path = options.fetch(:file_path)
  @bucket = options.fetch(:bucket)

  # Optional options
  @file = options[:file]
  @acl = options[:acl]
end
store(file_path:, file:, bucket:, acl: "private") click to toggle source
# File lib/file_manager/s3.rb, line 6
def store(file_path:, file:, bucket:, acl: "private")
  new(file_path: file_path, file: file, bucket: bucket, acl: acl).store
end

Public Instance Methods

delete() click to toggle source
# File lib/file_manager/s3.rb, line 19
def delete
  object.delete if @file_path
end
store() click to toggle source
# File lib/file_manager/s3.rb, line 15
def store
  object.put({acl: @acl, body: @file})
end

Private Instance Methods

bucket() click to toggle source
# File lib/file_manager/s3.rb, line 39
def bucket
  get_bucket_by(name: @bucket)
end
get_bucket_by(name:) click to toggle source
# File lib/file_manager/s3.rb, line 43
def get_bucket_by(name:)
  resource.bucket(name)
end
object() click to toggle source
# File lib/file_manager/s3.rb, line 35
def object
  bucket.object(@file_path)
end
resource() click to toggle source
# File lib/file_manager/s3.rb, line 47
def resource
  @resource ||= Aws::S3::Resource.new
end