class WithEvents::Worker
Public Instance Methods
perform(stream, event_name, appearance)
click to toggle source
# File lib/with_events/worker.rb, line 12 def perform(stream, event_name, appearance) events(stream, event_name, appearance).each do |event| event.options[:batch].call.each do |resource| call(event, resource) if may_call?(event, resource) end end reraise_last_exception end
Private Instance Methods
call(event, resource)
click to toggle source
rubocop:disable Lint/RescueWithoutErrorClass
# File lib/with_events/worker.rb, line 25 def call(event, resource) resource.public_send("#{event.name}!") rescue => e exceptions << e end
events(stream, name, appearance)
click to toggle source
# File lib/with_events/worker.rb, line 42 def events(stream, name, appearance) return [] unless stream(stream) @events ||= stream(stream).events.select do |event| event.name == name.to_sym && valid_event?(event, appearance) end end
exceptions()
click to toggle source
# File lib/with_events/worker.rb, line 50 def exceptions @exceptions ||= [] end
may_call?(event, resource)
click to toggle source
# File lib/with_events/worker.rb, line 31 def may_call?(event, resource) resource.public_send("#{event.name}?") rescue => e exceptions << e end
reraise_last_exception()
click to toggle source
# File lib/with_events/worker.rb, line 54 def reraise_last_exception raise exceptions.last if exceptions.size.positive? end
stream(stream)
click to toggle source
rubocop:enable Lint/RescueWithoutErrorClass
# File lib/with_events/worker.rb, line 38 def stream(stream) @stream ||= Stream.find(stream.to_sym) end