Class: Notebook::StorageAdapters::S3

Inherits:
Base
  • Object
show all
Defined in:
lib/notebook/storage_adapters/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get

Constructor Details

#initialize(attachment, options = {}) ⇒ S3

Returns a new instance of S3.



19
20
21
22
23
24
# File 'lib/notebook/storage_adapters/s3.rb', line 19

def initialize(attachment, options = {})
  super
  #--
  check_valid_credentials
  setup_s3
end

Instance Attribute Details

#s3_file_keyObject (readonly)

Returns the value of attribute s3_file_key.



17
18
19
# File 'lib/notebook/storage_adapters/s3.rb', line 17

def s3_file_key
  @s3_file_key
end

Instance Method Details

#deleteObject



26
27
28
# File 'lib/notebook/storage_adapters/s3.rb', line 26

def delete
  @bucket.object(@s3_file_key).delete
end

#uploadObject



30
31
32
33
34
# File 'lib/notebook/storage_adapters/s3.rb', line 30

def upload
  @s3_file_key = "#{SecureRandom.uuid}/#{File.basename(attachment.file)}"
  @file_object = @bucket.object(@s3_file_key)
  @file_object.upload_file(attachment.file.path)
end

#urlObject



36
37
38
# File 'lib/notebook/storage_adapters/s3.rb', line 36

def url
  @bucket.object(@s3_file_key).presigned_url(:get)
end