Module: RecordsUploads::Concern

Extended by:
ActiveSupport::Concern
Included in:
AttachmentUploader, AvatarUploader, DesignManagement::DesignV432x230Uploader, FileUploader, MetricImageUploader
Defined in:
app/uploaders/records_uploads.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#uploadObject

Returns the value of attribute upload.


7
8
9
# File 'app/uploaders/records_uploads.rb', line 7

def upload
  @upload
end

Instance Method Details

#filenameObject


41
42
43
# File 'app/uploaders/records_uploads.rb', line 41

def filename
  upload&.path ? File.basename(upload.path) : super
end

#readd_uploadObject


29
30
31
32
33
34
# File 'app/uploaders/records_uploads.rb', line 29

def readd_upload
  uploads.where(model: model, path: upload_path).delete_all
  upload.delete if upload

  self.upload = build_upload.tap(&:save!)
end

#record_upload(_tempfile = nil) ⇒ Object

After storing an attachment, create a corresponding Upload record

NOTE: We're ignoring the argument passed to this callback because we want the `SanitizedFile` object from `CarrierWave::Uploader::Base#file`, not the `Tempfile` object the callback gets.

Called `after :store` rubocop: disable CodeReuse/ActiveRecord


22
23
24
25
26
27
# File 'app/uploaders/records_uploads.rb', line 22

def record_upload(_tempfile = nil)
  return unless model
  return unless file && file.exists?

  Upload.transaction { readd_upload }
end

#upload_pathObject

rubocop: enable CodeReuse/ActiveRecord


37
38
39
# File 'app/uploaders/records_uploads.rb', line 37

def upload_path
  File.join(store_dir, filename.to_s)
end