lib/reactor/event.rb in reactor-0.5.3 vs lib/reactor/event.rb in reactor-0.6.0

- old
+ new

@@ -11,20 +11,12 @@ end end def perform(name, data) data.merge!(fired_at: Time.current, name: name) - Reactor::Subscriber.where(event: name).each do |subscriber| - Reactor::Subscriber.delay.fire subscriber.id, data - end - - #TODO: support more matching? - Reactor::Subscriber.where(event: '*').each do |s| - Reactor::Subscriber.delay.fire s.id, data - end - - ((Reactor::SUBSCRIBERS[name.to_s] || []) | (Reactor::SUBSCRIBERS['*'] || [])).each {|s| s.perform_async(data) } + fire_database_driven_subscribers(data, name) + fire_block_subscribers(data, name) end def method_missing(method, *args) if method.to_s.include?('=') try_setter(method, *args) @@ -88,7 +80,22 @@ data.has_key?("#{method}_type") end def initialize_polymorphic_association(method) data["#{method}_type"].constantize.find(data["#{method}_id"]) + end + + def fire_database_driven_subscribers(data, name) + Reactor::Subscriber.where(event: name).each do |subscriber| + Reactor::Subscriber.delay.fire subscriber.id, data + end + + #TODO: support more matching? + Reactor::Subscriber.where(event: '*').each do |s| + Reactor::Subscriber.delay.fire s.id, data + end + end + + def fire_block_subscribers(data, name) + ((Reactor::SUBSCRIBERS[name.to_s] || []) | (Reactor::SUBSCRIBERS['*'] || [])).each { |s| s.perform_where_needed(data) } end end