Class: Triggerable::Rules::Automation

Inherits:
Rule
  • Object
show all
Defined in:
lib/triggerable/rules/automation.rb

Instance Attribute Summary

Attributes inherited from Rule

#actions, #condition, #model, #name

Instance Method Summary collapse

Methods inherited from Rule

#initialize

Constructor Details

This class inherits a constructor from Triggerable::Rules::Rule

Instance Method Details

#execute!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/triggerable/rules/automation.rb', line 4

def execute!
  ids = ActiveRecord::Base.connection.execute(build_query).map { |r| r['id'] }
  models = model.where(id: ids)

  Triggerable::Engine.log(:debug, "#{desc}: processing #{models.count} object(s)")

  models.each do |object|
    begin
      actions.each {|a| a.run_for!(object, name)}
    rescue Exception => ex
      Triggerable::Engine.log(:error, "#{desc} failed with exception #{ex}")
    end
  end
end