Class: CarrierWave::Storage::Gcloud

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_connection_cache!Object



9
10
11
# File 'lib/carrierwave/storage/gcloud.rb', line 9

def self.clear_connection_cache!
  @connection_cache = {}
end

.connection_cacheObject



5
6
7
# File 'lib/carrierwave/storage/gcloud.rb', line 5

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

Instance Method Details

#connectionObject



23
24
25
26
27
28
29
# File 'lib/carrierwave/storage/gcloud.rb', line 23

def connection
  @connection ||= begin
    cert_path = Gem.loaded_specs['google-api-client'].full_gem_path+'/lib/cacerts.pem'
    ENV['SSL_CERT_FILE'] = cert_path
    self.class.connection_cache[credentials] ||= ::Gcloud.new(credentials[:gcloud_project] || ENV["GCLOUD_PROJECT"], credentials[:gcloud_keyfile] || ENV["GCLOUD_KEYFILE"]).storage
  end
end

#credentialsObject



31
32
33
# File 'lib/carrierwave/storage/gcloud.rb', line 31

def credentials
  uploader.gcloud_credentials
end

#retrieve!(identifier) ⇒ Object



19
20
21
# File 'lib/carrierwave/storage/gcloud.rb', line 19

def retrieve!(identifier)
  CarrierWave::Storage::GcloudFile.new(uploader, connection, uploader.store_path(identifier)).retrieve
end

#store!(file) ⇒ Object



13
14
15
16
17
# File 'lib/carrierwave/storage/gcloud.rb', line 13

def store!(file)
  CarrierWave::Storage::GcloudFile.new(uploader, connection, uploader.store_path).tap do |gcloud_file|
    gcloud_file.store(file)
  end
end