Class: ActiveTouch::TouchJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/active_touch/touch_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(record, association, after_touch) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_touch/touch_job.rb', line 4

def perform(record, association, after_touch)
  if association == 'self'
    associated = record
  else
    associated = record.send(association)
  end

  if associated.is_a? ActiveRecord::Base
    associated.update_columns(updated_at: record.updated_at)
    associated.send(after_touch) unless after_touch.blank?

  else
    associated.update_all(updated_at: record.updated_at)
    associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
  end
end