Module: MultiEncoder::Storage::AWS
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/multi_encoder/storage/aws.rb
Instance Method Summary collapse
- #aws_directory ⇒ Object
- #delete ⇒ Object
- #directory ⇒ Object
- #exists? ⇒ Boolean
- #file ⇒ Object
- #file_path ⇒ Object
- #root ⇒ Object
- #save ⇒ Object
- #url ⇒ Object
Instance Method Details
#aws_directory ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/multi_encoder/storage/aws.rb', line 26 def aws_directory env = defined?(Rails) ? Rails.env : 'gem-dev' @aws_directory ||= connection.directories.create({ key: "#{Storage.aws_bucket_prefix}-#{env}-#{type}", public: true }) end |
#delete ⇒ Object
51 52 53 |
# File 'lib/multi_encoder/storage/aws.rb', line 51 def delete file.destroy end |
#directory ⇒ Object
22 23 24 |
# File 'lib/multi_encoder/storage/aws.rb', line 22 def directory root.join 'public', 'system', type, *fingerprint end |
#exists? ⇒ Boolean
38 39 40 |
# File 'lib/multi_encoder/storage/aws.rb', line 38 def exists? !!aws_directory.files.head(filename) end |
#file ⇒ Object
14 15 16 |
# File 'lib/multi_encoder/storage/aws.rb', line 14 def file @file ||= aws_directory.files.get(filename) end |
#file_path ⇒ Object
34 35 36 |
# File 'lib/multi_encoder/storage/aws.rb', line 34 def file_path Pathname.new "/tmp/#{filename}.png" end |
#root ⇒ Object
18 19 20 |
# File 'lib/multi_encoder/storage/aws.rb', line 18 def root Pathname.new('/tmp') end |
#save ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/multi_encoder/storage/aws.rb', line 42 def save aws_directory.files.create({ body: IO.read(file_path), key: filename, public: true, content_type: 'image/png' }) end |
#url ⇒ Object
10 11 12 |
# File 'lib/multi_encoder/storage/aws.rb', line 10 def url file.public_url end |