class Refile::Backgrounder::StoreWorker

Attributes

attachment_name[R]
record[R]

Public Instance Methods

perform(record, attachment_name) { || ... } click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 7
def perform(record, attachment_name)
  @record = record
  @attachment_name = attachment_name
  return unless attachment_cached?

  file = upload attacher.get
  cleanup_cache!
  update_record_attachment(file) if file
  yield if block_given?
end

Private Instance Methods

attacher() click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 20
def attacher
  @_attacher ||= record.send("#{attachment_name}_attacher")
end
attachment_cached?() click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 24
def attachment_cached?
  attacher.cache_id
end
cleanup_cache!() click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 32
def cleanup_cache!
  attacher.delete!
end
update_record_attachment(file) click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 36
def update_record_attachment(file)
  record._skip_refile_backgrounder = true
  record.send "#{attachment_name}_cache_id=", nil if record.respond_to? "#{attachment_name}_cache_id="
  record.send "#{attachment_name}_id=", file.id  if record.respond_to? "#{attachment_name}_id="
  record.send "#{attachment_name}_id_will_change!" if record.respond_to? "#{attachment_name}_id_will_change!"
  record.send "#{attachment_name}_cache_id_will_change!" if record.respond_to? "#{attachment_name}_cache_id_will_change!"
  record.save
end
upload(file) click to toggle source
# File lib/refile/backgrounder/store_worker.rb, line 28
def upload(file)
  attacher.store.upload(file)
end