Module: RecordsUploads::Concern
- Extended by:
- ActiveSupport::Concern
- Included in:
- AttachmentUploader, AvatarUploader, DesignManagement::DesignV432x230Uploader, FileUploader, MetricImageUploader
- Defined in:
- app/uploaders/records_uploads.rb
Constant Summary collapse
- VERSION =
This value is stored in ‘uploads.version`. Increment this value to have functionality that only applies to certain versions of uploads.
2
Instance Attribute Summary collapse
-
#upload ⇒ Object
Returns the value of attribute upload.
Instance Method Summary collapse
- #filename ⇒ Object
- #readd_upload ⇒ Object
-
#record_upload(_tempfile = nil) ⇒ Object
After storing an attachment, create a corresponding Upload record.
-
#upload_path ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
Instance Attribute Details
#upload ⇒ Object
Returns the value of attribute upload.
11 12 13 |
# File 'app/uploaders/records_uploads.rb', line 11 def upload @upload end |
Instance Method Details
#filename ⇒ Object
49 50 51 |
# File 'app/uploaders/records_uploads.rb', line 49 def filename upload&.path ? File.basename(upload.path) : super end |
#readd_upload ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/uploaders/records_uploads.rb', line 33 def readd_upload Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.temporary_ignore_tables_in_transaction( %w[uploads], url: "https://gitlab.com/gitlab-org/gitlab/-/issues/398199" ) do uploads.where(model: model, path: upload_path).delete_all upload.delete if upload self.upload = build_upload.tap(&:save!) end 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
26 27 28 29 30 31 |
# File 'app/uploaders/records_uploads.rb', line 26 def record_upload(_tempfile = nil) return unless model return unless file && file.exists? Upload.transaction { readd_upload } end |
#upload_path ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
45 46 47 |
# File 'app/uploaders/records_uploads.rb', line 45 def upload_path File.join(store_dir, filename.to_s) end |