Class: Cloudinary::PreloadedFile
- Defined in:
- lib/cloudinary/preloaded_file.rb
Direct Known Subclasses
CarrierWave::PreloadedCloudinaryFile, CarrierWave::StoredFile
Constant Summary collapse
- PRELOADED_CLOUDINARY_PATH =
/^([^\/]+)\/([^\/]+)\/v(\d+)\/([^#]+)#([^\/]+)$/
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#public_id ⇒ Object
readonly
Returns the value of attribute public_id.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #identifier ⇒ Object
-
#initialize(file_info) ⇒ PreloadedFile
constructor
A new instance of PreloadedFile.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(file_info) ⇒ PreloadedFile
Returns a new instance of PreloadedFile.
5 6 7 8 |
# File 'lib/cloudinary/preloaded_file.rb', line 5 def initialize(file_info) @resource_type, @type, @version, @filename, @signature = file_info.scan(PRELOADED_CLOUDINARY_PATH).first @public_id, @format = Cloudinary::PreloadedFile.split_format(@filename) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def format @format end |
#public_id ⇒ Object (readonly)
Returns the value of attribute public_id.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def public_id @public_id end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def resource_type @resource_type end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def signature @signature end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/cloudinary/preloaded_file.rb', line 4 def version @version end |
Class Method Details
.split_format(identifier) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/cloudinary/preloaded_file.rb', line 24 def self.split_format(identifier) last_dot = identifier.rindex(".") return [identifier, nil] if last_dot.nil? public_id = identifier[0, last_dot] format = identifier[last_dot+1..-1] return [public_id, format] end |
Instance Method Details
#identifier ⇒ Object
16 17 18 |
# File 'lib/cloudinary/preloaded_file.rb', line 16 def identifier "v#{version}/#{filename}" end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/cloudinary/preloaded_file.rb', line 20 def to_s "#{resource_type}/#{type}/v#{version}/#{filename}##{signature}" end |
#valid? ⇒ Boolean
10 11 12 13 14 |
# File 'lib/cloudinary/preloaded_file.rb', line 10 def valid? public_id = @resource_type == "raw" ? self.filename : self.public_id expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>public_id, :version=>version}, Cloudinary.config.api_secret) @signature == expected_signature end |