Sha256: 5fb490fcf20a3f3c643232e07b781a3d18f6e51ec7795d5ddf765e9cb0aee24a
Contents?: true
Size: 613 Bytes
Versions: 2
Compression:
Stored size: 613 Bytes
Contents
# frozen_string_literal: true require_relative 'reduction' module Rack module Reducer # Mount Rack::Reducer as middleware class Middleware def initialize(app, options = {}) @app = app @key = options[:key] || 'rack.reduction' @props = options end # Call the next app in the middleware stack, with env[key] set # to the ouput of a reduction def call(env) params = Rack::Request.new(env).params reduction = Reduction.new(@props.merge(params: params)).reduce @app.call env.merge(@key => reduction) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rack-reducer-0.1.2 | lib/rack/reducer/middleware.rb |
rack-reducer-0.1.1 | lib/rack/reducer/middleware.rb |