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.
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
145 146 147 |
# File 'lib/cloudinary/carrier_wave.rb', line 145 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
145 146 147 |
# File 'lib/cloudinary/carrier_wave.rb', line 145 def format @format end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
145 146 147 |
# File 'lib/cloudinary/carrier_wave.rb', line 145 def identifier @identifier end |
#public_id ⇒ Object (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_type ⇒ Object (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_type ⇒ Object (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 |
#version ⇒ Object (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
#delete ⇒ Object
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
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(={}) parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge() Cloudinary::Downloader.download(self.identifier, parameters) end |
#storage_identifier ⇒ Object
168 169 170 |
# File 'lib/cloudinary/carrier_wave.rb', line 168 def storage_identifier identifier end |