Class: Routemaster::Middleware::Siphon
- Inherits:
-
Object
- Object
- Routemaster::Middleware::Siphon
- Defined in:
- lib/routemaster/middleware/siphon.rb
Overview
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
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Siphon
constructor
A new instance of Siphon.
Constructor Details
#initialize(app, options = {}) ⇒ Siphon
Returns a new instance of Siphon.
9 10 11 12 |
# File 'lib/routemaster/middleware/siphon.rb', line 9 def initialize(app, = {}) @app = app @processors = .fetch(:siphon_events) { {} } end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# 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 |