class Routemaster::Middleware::Siphon

Filters out events based on their topic and passes them to a handling class

‘use Middleware::Siphon, ’siphon_events’ => {‘some_topic’ => SomeTopicHandler`}

Topic handlers are initialized with the full event payload and must respond to `#call`

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/routemaster/middleware/siphon.rb, line 9
def initialize(app, options = {})
  @app = app
  @processors = options.fetch(:siphon_events) { {} }
end

Public Instance Methods

call(env) click to toggle source
# File lib/routemaster/middleware/siphon.rb, line 14
def call(env)
  siphoned, non_siphoned = env.fetch('routemaster.payload', []).partition do |event|
    topics_to_siphon.include? event['topic']
  end
  siphoned.each do |event|
    @processors[event['topic']].new(event).call
  end
  env['routemaster.payload'] = non_siphoned
  @app.call(env)
end

Private Instance Methods

topics_to_siphon() click to toggle source
# File lib/routemaster/middleware/siphon.rb, line 27
def topics_to_siphon
  @topics_to_siphon ||= @processors.keys.map(&:to_s)
end