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, is_async = ActiveTouch.configuration.async) ⇒ Object



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

def perform(record, association, after_touch, is_async = ActiveTouch.configuration.async)
  associated = association == 'self' ? record : record.send(association)

  if associated.is_a? ActiveRecord::Base
    unless ActiveTouch.configuration.timestamp_attribute.nil?
      associated.update_columns(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
    end

    associated.send(after_touch) unless after_touch.blank?

  elsif !associated.nil? && !associated.empty?
    unless ActiveTouch.configuration.timestamp_attribute.nil?
      associated.update_all(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
    end

    associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
  end
end