Class: CarrierWave::Storage::AWS

Inherits:
Abstract
  • Object
show all
Defined in:
lib/carrierwave/storage/aws.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_connection_cache!Object



12
13
14
# File 'lib/carrierwave/storage/aws.rb', line 12

def self.clear_connection_cache!
  @connection_cache = {}
end

.connection_cacheObject



8
9
10
# File 'lib/carrierwave/storage/aws.rb', line 8

def self.connection_cache
  @connection_cache ||= {}
end

Instance Method Details

#cache!(file) ⇒ Object



26
27
28
29
30
# File 'lib/carrierwave/storage/aws.rb', line 26

def cache!(file)
  AWSFile.new(uploader, connection, uploader.cache_path).tap do |aws_file|
    aws_file.store(file)
  end
end

#clean_cache!(_seconds) ⇒ Object



40
41
42
# File 'lib/carrierwave/storage/aws.rb', line 40

def clean_cache!(_seconds)
  raise 'use Object Lifecycle Management to clean the cache'
end

#connectionObject



44
45
46
47
48
49
50
# File 'lib/carrierwave/storage/aws.rb', line 44

def connection
  @connection ||= begin
    conn_cache = self.class.connection_cache

    conn_cache[credentials] ||= ::Aws::S3::Resource.new(*credentials)
  end
end

#credentialsObject



52
53
54
# File 'lib/carrierwave/storage/aws.rb', line 52

def credentials
  [uploader.aws_credentials].compact
end

#delete_dir!(path) ⇒ Object



36
37
38
# File 'lib/carrierwave/storage/aws.rb', line 36

def delete_dir!(path)
  # NOTE: noop, because there are no directories on S3
end

#retrieve!(identifier) ⇒ Object



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

def retrieve!(identifier)
  AWSFile.new(uploader, connection, uploader.store_path(identifier))
end

#retrieve_from_cache!(identifier) ⇒ Object



32
33
34
# File 'lib/carrierwave/storage/aws.rb', line 32

def retrieve_from_cache!(identifier)
  AWSFile.new(uploader, connection, uploader.cache_path(identifier))
end

#store!(file) ⇒ Object



16
17
18
19
20
# File 'lib/carrierwave/storage/aws.rb', line 16

def store!(file)
  AWSFile.new(uploader, connection, uploader.store_path).tap do |aws_file|
    aws_file.store(file)
  end
end