Class: Triggerable::Rules::Automation
- Defined in:
- lib/triggerable/rules/automation.rb
Instance Attribute Summary collapse
-
#pass_relation ⇒ Object
Returns the value of attribute pass_relation.
Attributes inherited from Rule
#actions, #condition, #model, #name
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(model, options, block) ⇒ Automation
constructor
A new instance of Automation.
Constructor Details
#initialize(model, options, block) ⇒ Automation
Returns a new instance of Automation.
6 7 8 9 10 |
# File 'lib/triggerable/rules/automation.rb', line 6 def initialize model, , block super(model, , block) @pass_relation = [:pass_relation] @unscoped = [:unscoped] end |
Instance Attribute Details
#pass_relation ⇒ Object
Returns the value of attribute pass_relation.
4 5 6 |
# File 'lib/triggerable/rules/automation.rb', line 4 def pass_relation @pass_relation end |
Instance Method Details
#execute! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/triggerable/rules/automation.rb', line 12 def execute! ids = ActiveRecord::Base.connection.execute(build_query).map { |r| r['id'] } models = @unscoped ? model.unscoped : model models = models.where(id: ids) Triggerable::Engine.log(:debug, "#{desc}: processing #{models.count} object(s)") if @pass_relation execute_on!(models) else models.each { |object| execute_on!(object) } end end |