Class: Rack::Reducer::Middleware
- Inherits:
-
Object
- Object
- Rack::Reducer::Middleware
- Defined in:
- lib/rack/reducer/middleware.rb
Overview
Mount Rack::Reducer as middleware
Instance Method Summary collapse
-
#call(env) ⇒ Object
Call the next app in the middleware stack, with ‘env` set to the ouput of a reduction.
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
22 23 24 25 26 |
# File 'lib/rack/reducer/middleware.rb', line 22 def initialize(app, = {}) @app = app @key = [:key] || 'rack.reduction' @reducer = Rack::Reducer.new([:dataset], *[:filters]) end |
Instance Method Details
#call(env) ⇒ Object
Call the next app in the middleware stack, with ‘env` set to the ouput of a reduction
30 31 32 33 34 |
# File 'lib/rack/reducer/middleware.rb', line 30 def call(env) params = Rack::Request.new(env).params reduction = @reducer.apply(params) @app.call env.merge(@key => reduction) end |