class CarrierWave::Storage::GcloudFile

Constants

GCLOUD_STORAGE_URL

Attributes

connection[RW]
file[W]
file_exists[RW]
gcloud_options[RW]
path[RW]
uploader[RW]

Public Class Methods

new(uploader, connection, path) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 13
def initialize(uploader, connection, path)
  @uploader   = uploader
  @connection = connection
  @path       = path
end

Public Instance Methods

attributes() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 24
def attributes
  return unless exists?
  {
    content_type: file.content_type,
    size: file.size,
    updated_at: file.updated_at.to_s,
    etag: file.etag
  }
end
authenticated_url(options = {}) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 86
def authenticated_url(options = {})
  bucket.signed_url(path, options)
end
copy_to(new_path) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 75
def copy_to(new_path)
  file.copy(
    new_path,
    acl: uploader.gcloud_bucket_is_public ? 'publicRead' : nil
  )
end
delete() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 34
def delete
  deleted = file ? file.delete : true
  @file = nil if deleted
  deleted
end
exists?() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 40
def exists?
  !file.nil?
end
extension() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 44
def extension
  elements = path.split('.')
  elements.last if elements.size > 1
end
file() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 19
def file
  @file ||= bucket.file(path)
end
Also aliased as: to_file
filename(options = {}) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 49
def filename(options = {})
  CarrierWave::Support::UriFilename.filename(file.url)
end
public_url() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 90
def public_url
  if uploader.asset_host
    "#{uploader.asset_host}/#{path}"
  else
    "#{GCLOUD_STORAGE_URL}/#{uploader.gcloud_bucket}/#{@path}"
  end
end
read() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 53
def read
  tmp_file = Tempfile.new(
    CarrierWave::Support::UriFilename.filename(file.name)
  )
  (file.download tmp_file.path, verify: :all).read
end
store(new_file) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 60
def store(new_file)
  if new_file.is_a?(self.class)
    new_file.copy_to(path)
  else
    @file = bucket.create_file(
      new_file.path,
      path,
      acl: uploader.gcloud_bucket_is_public ? 'publicRead' : nil,
      content_type: new_file.content_type,
      content_disposition: uploader.gcloud_content_disposition
    )
  end
  self
end
to_file()
Alias for: file
url(options = {}) click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 82
def url(options = {})
  uploader.gcloud_bucket_is_public ? public_url : authenticated_url(options)
end

Private Instance Methods

bucket() click to toggle source
# File lib/carrierwave/storage/gcloud_file.rb, line 100
def bucket
  @bucket ||= connection.bucket(uploader.gcloud_bucket, skip_lookup: true)
end