lib/reactor/models/concerns/eventable.rb in reactor-0.1.1 vs lib/reactor/models/concerns/eventable.rb in reactor-0.1.2
- old
+ new
@@ -25,20 +25,38 @@
def schedule_events
self.class.events.each do |name, data|
data = data.merge(
at: ( data[:at] ? send(data[:at]) : nil), actor: self
).except(:watch)
- Reactor::Event.delay.publish name, data
+ need_to_fire = case (ifarg = data[:if])
+ when Proc
+ what = instance_exec &ifarg
+ when Symbol
+ send(ifarg)
+ else
+ true
+ end
+ Reactor::Event.delay.publish name, data if need_to_fire
end
end
def reschedule_events
self.class.events.each do |name, data|
if data[:at] && send("#{data[:watch] || data[:at]}_changed?")
Reactor::Event.delay.reschedule name,
at: send(data[:at]),
actor: self,
was: send("#{data[:at]}_was")
+ end
+
+ if data[:if]
+ need_to_fire = case (ifarg = data[:if])
+ when Proc
+ instance_exec &ifarg
+ when Symbol
+ send(ifarg)
+ end
+ Reactor::Event.delay.publish name, actor: self if need_to_fire
end
end
end
end
\ No newline at end of file