class Cloudinary::CarrierWave::CloudinaryFile

Attributes

filename[R]
format[R]
identifier[R]
public_id[R]
resource_type[R]
storage_type[R]
version[R]

Public Class Methods

new(identifier, uploader) click to toggle source
# File lib/cloudinary/carrier_wave.rb, line 152
def initialize(identifier, uploader)
  @uploader = uploader
  @identifier = identifier

  if @identifier.match(%r(^(image|raw|video)/(upload|private|authenticated)(?:/v([0-9]+))?/(.*)))
    @resource_type = $1
    @storage_type = $2
    @version = $3.presence
    @filename = $4
  elsif @identifier.match(%r(^v([0-9]+)/(.*)))
    @version = $1
    @filename = $2
  else
    @filename = @identifier
    @version = nil
  end

  @storage_type ||= uploader.class.storage_type
  @resource_type ||= Cloudinary::Utils.resource_type_for_format(@filename)
  @public_id, @format = Cloudinary::PreloadedFile.split_format(@filename)
end

Public Instance Methods

delete() click to toggle source
# File lib/cloudinary/carrier_wave.rb, line 178
def delete
  public_id = @resource_type == "raw" ? self.filename : self.public_id
  Cloudinary::Uploader.destroy(public_id, :type=>self.storage_type, :resource_type=>self.resource_type) if @uploader.delete_remote?
end
exists?() click to toggle source
# File lib/cloudinary/carrier_wave.rb, line 183
def exists?
  public_id = @resource_type == "raw" ? self.filename : self.public_id
  Cloudinary::Uploader.exists?(public_id, :version=>self.version, :type=>self.storage_type, :resource_type=>self.resource_type)
end
read(options={}) click to toggle source
# File lib/cloudinary/carrier_wave.rb, line 188
def read(options={})
  parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge(options)
  Cloudinary::Downloader.download(self.identifier, parameters)
end
storage_identifier() click to toggle source
# File lib/cloudinary/carrier_wave.rb, line 174
def storage_identifier
  identifier
end