Class: Cloudinary::PreloadedFile

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

Constant Summary collapse

PRELOADED_CLOUDINARY_PATH =
/^([^\/]+)\/([^\/]+)\/v(\d+)\/([^#]+)#([^\/]+)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/cloudinary/preloaded_file.rb', line 4

def filename
  @filename
end

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'lib/cloudinary/preloaded_file.rb', line 4

def format
  @format
end

#public_idObject (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_typeObject (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

#signatureObject (readonly)

Returns the value of attribute signature.



4
5
6
# File 'lib/cloudinary/preloaded_file.rb', line 4

def signature
  @signature
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/cloudinary/preloaded_file.rb', line 4

def type
  @type
end

#versionObject (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

#identifierObject



16
17
18
# File 'lib/cloudinary/preloaded_file.rb', line 16

def identifier
  "v#{version}/#{filename}"
end

#to_sObject



20
21
22
# File 'lib/cloudinary/preloaded_file.rb', line 20

def to_s
  "#{resource_type}/#{type}/v#{version}/#{filename}##{signature}"
end

#valid?Boolean

Returns:

  • (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