Class: Rack::Reducer::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/reducer/middleware.rb

Overview

Mount Rack::Reducer as middleware

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Middleware.



8
9
10
11
12
# File 'lib/rack/reducer/middleware.rb', line 8

def initialize(app, options = {})
  @app = app
  @key = options[:key] || 'rack.reduction'
  @props = options
end

Instance Method Details

#call(env) ⇒ Object

Call the next app in the middleware stack, with env set to the ouput of a reduction



16
17
18
19
20
# File 'lib/rack/reducer/middleware.rb', line 16

def call(env)
  params = Rack::Request.new(env).params
  reduction = Reduction.new(@props.merge(params: params)).reduce
  @app.call env.merge(@key => reduction)
end