lib/reactor/models/concerns/publishable.rb in reactor-0.4.6 vs lib/reactor/models/concerns/publishable.rb in reactor-0.4.7

- old
+ new

@@ -1,10 +1,10 @@ module Reactor::Publishable extend ActiveSupport::Concern included do - after_commit :schedule_events, if: :persisted?, on: :create + after_commit :schedule_events, if: :persisted? after_commit :reschedule_events, if: :persisted?, on: :update end def publish(name, data = {}) Reactor::Event.publish(name, data.merge(actor: self) ) @@ -29,37 +29,30 @@ target: ( data[:target] ? self : nil), at: ( data[:at] ? send(data[:at]) : nil) ).except(:watch, :if) need_to_fire = case (ifarg = data[:if]) when Proc - instance_exec &ifarg + instance_exec(&ifarg) when Symbol send(ifarg) else - true + transaction_include_action?(:create) end Reactor::Event.publish name, event if need_to_fire end end def reschedule_events self.class.events.each do |name, data| attr_changed_method = data[:watch] || data[:at] if data[:at] && previous_changes[attr_changed_method] Reactor::Event.reschedule name, - at: send(data[:at]), - actor: ( data[:actor] ? send(data[:actor]) : self ), - target: ( data[:target] ? self : nil), - was: previous_changes[data[:at]].try(:first) || send("#{data[:at]}_was") + data.merge( + at: send(data[:at]), + actor: ( data[:actor] ? send(data[:actor]) : self ), + target: ( data[:target] ? self : nil), + was: previous_changes[data[:at]].try(:first) || 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.publish name, actor: self if need_to_fire - end end end -end \ No newline at end of file + +end