Class: Uploadcare::Rails::File
- Inherits:
-
Entity::File
- Object
- Entity::File
- Uploadcare::Rails::File
show all
- Includes:
- Objects::Loadable
- Defined in:
- lib/uploadcare/rails/objects/file.rb
Overview
A wrapper class for Uploadcare::File object. Allows caching loaded files and has methods for Rails model attributes
Constant Summary
collapse
- ATTR_ENTITIES =
[:cdn_url].freeze
Instance Method Summary
collapse
#cache_expires_in, #cache_key, #caching_enabled?, #update_attrs, #uploadcare_configuration
Instance Method Details
#delete ⇒ Object
31
32
33
|
# File 'lib/uploadcare/rails/objects/file.rb', line 31
def delete
Uploadcare::FileApi.delete_file(uuid)
end
|
#load ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/uploadcare/rails/objects/file.rb', line 39
def load
file_info = if caching_enabled?
::Rails.cache.fetch(cache_key, expires_in: cache_expires_in) do
request_file_info_from_api
end
else
request_file_info_from_api
end
update_attrs(file_info)
end
|
#loaded? ⇒ Boolean
50
51
52
|
# File 'lib/uploadcare/rails/objects/file.rb', line 50
def loaded?
datetime_uploaded.present?
end
|
#store ⇒ Object
25
26
27
28
29
|
# File 'lib/uploadcare/rails/objects/file.rb', line 25
def store
file_info = Uploadcare::FileApi.store_file(uuid).merge(cdn_url: cdn_url).to_h
::Rails.cache.write(cache_key, file_info, expires_in: cache_expires_in) if caching_enabled?
update_attrs(file_info)
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/uploadcare/rails/objects/file.rb', line 35
def to_s
cdn_url
end
|
18
19
20
21
22
23
|
# File 'lib/uploadcare/rails/objects/file.rb', line 18
def transform_url(transformations, transformator_class = Uploadcare::Rails::Transformations::ImageTransformations)
return if cdn_url.blank?
transformations_query = transformator_class.new(transformations).call if transformations.present?
[cdn_url, transformations_query].compact.join('-')
end
|