Class: Triggerable::Rules::Trigger

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

Instance Attribute Summary collapse

Attributes inherited from Rule

#actions, #condition, #model, #name

Instance Method Summary collapse

Constructor Details

#initialize(model, options, block) ⇒ Trigger

Returns a new instance of Trigger.



6
7
8
9
# File 'lib/triggerable/rules/trigger.rb', line 6

def initialize model, options, block
  super
  @callback  = options[:on]
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



4
5
6
# File 'lib/triggerable/rules/trigger.rb', line 4

def callback
  @callback
end

Instance Method Details

#execute!(object) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/triggerable/rules/trigger.rb', line 11

def execute! object
  return unless condition.true_for?(object)

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