Class: Routemaster::Middleware::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/routemaster/middleware/filter.rb

Overview

Filters event payloads passed in the environment (in env['routemaster.payload']), is any.

Will use Routemaster::Dirty::Filter by default.

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Filter

options[:filter] [Routemaster::Dirty::Filter] an event filter (optional; will be created using the redis and expiry options if not provided)



12
13
14
15
# File 'lib/routemaster/middleware/filter.rb', line 12

def initialize(app, options = {})
  @app    = app
  @filter = options.fetch(:filter) { Routemaster::Dirty::Filter.new }
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/routemaster/middleware/filter.rb', line 17

def call(env)
  payload = env['routemaster.payload']
  if payload && payload.any?
    env['routemaster.payload'] = @filter.run(payload)
  end
  @app.call(env)
end