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



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

def self.clear_connection_cache!
  @connection_cache = {}
end

.connection_cacheObject



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

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

Instance Method Details

#connectionObject



28
29
30
31
32
33
34
# File 'lib/carrierwave/storage/aws.rb', line 28

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

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

#credentialsObject



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

def credentials
  [uploader.aws_credentials].compact
end

#retrieve!(identifier) ⇒ Object



24
25
26
# File 'lib/carrierwave/storage/aws.rb', line 24

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

#store!(file) ⇒ Object



18
19
20
21
22
# File 'lib/carrierwave/storage/aws.rb', line 18

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