Class: ShrinePromoteJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
lib/potassium/assets/app/jobs/shrine_promote_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(attacher_class, record_class, record_id, name, file_data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/potassium/assets/app/jobs/shrine_promote_job.rb', line 4

def perform(attacher_class, record_class, record_id, name, file_data)
  attacher_class = Object.const_get(attacher_class)
  record         = Object.const_get(record_class).find(record_id)

  attacher = attacher_class.retrieve(model: record, name: name, file: file_data)
  attacher.create_derivatives
  attacher.atomic_promote
rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound
  # attachment has changed or the record has been deleted, nothing to do
end