Module: MultiEncoder::Storage::AWS

Extended by:
ActiveSupport::Concern
Defined in:
lib/multi_encoder/storage/aws.rb

Instance Method Summary collapse

Instance Method Details

#aws_directoryObject



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

#deleteObject



51
52
53
# File 'lib/multi_encoder/storage/aws.rb', line 51

def delete
  file.destroy
end

#directoryObject



22
23
24
# File 'lib/multi_encoder/storage/aws.rb', line 22

def directory
  root.join 'public', 'system', type, *fingerprint
end

#exists?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/multi_encoder/storage/aws.rb', line 38

def exists?
  !!aws_directory.files.head(filename)
end

#fileObject



14
15
16
# File 'lib/multi_encoder/storage/aws.rb', line 14

def file
  @file ||= aws_directory.files.get(filename)
end

#file_pathObject



34
35
36
# File 'lib/multi_encoder/storage/aws.rb', line 34

def file_path
  Pathname.new "/tmp/#{filename}.png"
end

#rootObject



18
19
20
# File 'lib/multi_encoder/storage/aws.rb', line 18

def root
  Pathname.new('/tmp')
end

#saveObject



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

#urlObject



10
11
12
# File 'lib/multi_encoder/storage/aws.rb', line 10

def url
  file.public_url
end