Module: Uploadcare::Rails::Mongoid::MountUploadcareFile

Extended by:
ActiveSupport::Concern
Defined in:
lib/uploadcare/rails/mongoid/mount_uploadcare_file.rb

Overview

A module containing Mongoid extension. Allows using uploadcare file methods in Mongoid models

Instance Method Summary collapse

Instance Method Details

#build_uploadcare_file(attribute) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/uploadcare/rails/mongoid/mount_uploadcare_file.rb', line 17

def build_uploadcare_file(attribute)
  cdn_url = read_attribute(attribute).to_s
  return if cdn_url.empty?

  uuid = IdExtractor.call(cdn_url)
  cache_key = File.build_cache_key(cdn_url)
  default_attributes = { cdn_url: cdn_url, uuid: uuid.presence }
  file_attributes = ::Rails.cache.read(cache_key).presence || default_attributes
  Uploadcare::Rails::File.new(file_attributes)
end