Class: Cloudinary::CarrierWave::CloudinaryFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudinary/carrier_wave.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, uploader) ⇒ CloudinaryFile

Returns a new instance of CloudinaryFile.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/cloudinary/carrier_wave.rb', line 146

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

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def filename
  @filename
end

#formatObject (readonly)

Returns the value of attribute format.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def format
  @format
end

#identifierObject (readonly)

Returns the value of attribute identifier.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def identifier
  @identifier
end

#public_idObject (readonly)

Returns the value of attribute public_id.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def public_id
  @public_id
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def resource_type
  @resource_type
end

#storage_typeObject (readonly)

Returns the value of attribute storage_type.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def storage_type
  @storage_type
end

#versionObject (readonly)

Returns the value of attribute version.



145
146
147
# File 'lib/cloudinary/carrier_wave.rb', line 145

def version
  @version
end

Instance Method Details

#deleteObject



172
173
174
175
# File 'lib/cloudinary/carrier_wave.rb', line 172

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?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/cloudinary/carrier_wave.rb', line 177

def exists?
  Cloudinary::Uploader.exists?(self.identifier, :type=>self.storage_type, :resource_type=>self.resource_type)
end

#read(options = {}) ⇒ Object



181
182
183
184
# File 'lib/cloudinary/carrier_wave.rb', line 181

def read(options={})
  parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge(options)
  Cloudinary::Downloader.download(self.identifier, parameters)
end

#storage_identifierObject



168
169
170
# File 'lib/cloudinary/carrier_wave.rb', line 168

def storage_identifier
  identifier
end