Module: Uploadcare::Rails::Internal::AttachmentLoading
- Extended by:
- ActiveSupport::Concern
- Included in:
- AttachedFile, AttachedFiles
- Defined in:
- lib/uploadcare/rails/internal/attachment_loading.rb
Instance Method Summary collapse
- #cache_expires_in ⇒ Object
- #cache_identity ⇒ Object
- #cache_key ⇒ Object
- #caching_enabled? ⇒ Boolean
- #resource_to_hash(resource) ⇒ Object
- #update_attrs(new_attrs) ⇒ Object
- #uploadcare_configuration ⇒ Object
Instance Method Details
#cache_expires_in ⇒ Object
32 33 34 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 32 def cache_expires_in uploadcare_configuration.cache_expires_in end |
#cache_identity ⇒ Object
48 49 50 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 48 def cache_identity cdn_url end |
#cache_key ⇒ Object
44 45 46 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 44 def cache_key self.class.build_cache_key(cache_identity) end |
#caching_enabled? ⇒ Boolean
36 37 38 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 36 def caching_enabled? uploadcare_configuration.cache_files end |
#resource_to_hash(resource) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 52 def resource_to_hash(resource) return resource.to_h.transform_keys(&:to_s) if resource.respond_to?(:to_h) return resource.attributes.transform_keys(&:to_s) if resource.respond_to?(:attributes) if resource.class.const_defined?(:ATTRIBUTES, false) return resource.class::ATTRIBUTES.each_with_object({}) do |attribute, result| result[attribute.to_s] = resource.public_send(attribute) end end raise ArgumentError, "Unsupported Uploadcare resource #{resource.class}. Expected #to_h, #attributes, or class ATTRIBUTES." end |
#update_attrs(new_attrs) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 21 def update_attrs(new_attrs) return self if new_attrs.nil? raise ArgumentError, "new_attrs must be a Hash" unless new_attrs.is_a?(Hash) new_attrs.each do |key, value| setter = "#{key}=" public_send(setter, value) if respond_to?(setter) end self end |
#uploadcare_configuration ⇒ Object
40 41 42 |
# File 'lib/uploadcare/rails/internal/attachment_loading.rb', line 40 def uploadcare_configuration self.class.uploadcare_configuration end |