Class: Cloudinary::CarrierWave::CloudinaryFile
- Defined in:
- lib/cloudinary/carrier_wave.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#public_id ⇒ Object
readonly
Returns the value of attribute public_id.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#storage_type ⇒ Object
readonly
Returns the value of attribute storage_type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(identifier, uploader) ⇒ CloudinaryFile
constructor
A new instance of CloudinaryFile.
- #read(options = {}) ⇒ Object
- #storage_identifier ⇒ Object
Constructor Details
#initialize(identifier, uploader) ⇒ CloudinaryFile
Returns a new instance of CloudinaryFile.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# 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 |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def format @format end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def identifier @identifier end |
#public_id ⇒ Object (readonly)
Returns the value of attribute public_id.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def public_id @public_id end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def resource_type @resource_type end |
#storage_type ⇒ Object (readonly)
Returns the value of attribute storage_type.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def storage_type @storage_type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
151 152 153 |
# File 'lib/cloudinary/carrier_wave.rb', line 151 def version @version end |
Instance Method Details
#delete ⇒ Object
178 179 180 181 |
# 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? ⇒ Boolean
183 184 185 186 |
# 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 = {}) ⇒ Object
188 189 190 191 |
# File 'lib/cloudinary/carrier_wave.rb', line 188 def read(={}) parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge() Cloudinary::Downloader.download(self.identifier, parameters) end |
#storage_identifier ⇒ Object
174 175 176 |
# File 'lib/cloudinary/carrier_wave.rb', line 174 def storage_identifier identifier end |