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



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

def self.clear_connection_cache!
  @connection_cache = {}
end

.connection_cacheObject



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

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

Instance Method Details

#cache!(file) ⇒ Object



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

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

#clean_cache!(_seconds) ⇒ Object



38
39
40
# File 'lib/carrierwave/storage/gcloud.rb', line 38

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

#connectionObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/carrierwave/storage/gcloud.rb', line 42

def connection
  @connection ||= begin
    conn_cache = self.class.connection_cache
    ENV['SSL_CERT_FILE'] = cert_path
    conn_cache[credentials] ||= ::Google::Cloud.new(
      credentials[:gcloud_project] || ENV['GCLOUD_PROJECT'],
      credentials[:gcloud_keyfile] || ENV['GCLOUD_KEYFILE']
    ).storage
  end
end

#credentialsObject



53
54
55
# File 'lib/carrierwave/storage/gcloud.rb', line 53

def credentials
  uploader.gcloud_credentials || {}
end

#delete_dir!(path) ⇒ Object



34
35
36
# File 'lib/carrierwave/storage/gcloud.rb', line 34

def delete_dir!(path)
  # do nothing, because there's no such things as 'empty directory'
end

#retrieve!(identifier) ⇒ Object



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

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

#retrieve_from_cache!(identifier) ⇒ Object



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

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

#store!(file) ⇒ Object



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

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