class Wouter::Wrapper

`Wouter::Wrapper` is a class that provides a top level Rack application containing all the routing endpoints. HTTP requests come through `Wouter::Wrapper` and it dispatches to the appropriate route class that was defined by the user.

Public Class Methods

new(routes:, config: {}) click to toggle source
# File lib/wouter/wrapper.rb, line 8
def initialize(routes:, config: {})
  @routes = routes
  @config = config
end

Public Instance Methods

call(env) click to toggle source
# File lib/wouter/wrapper.rb, line 13
def call(env)
  env['wouter'] = @config
  request = Rack::Request.new(env)
  route = find_route(request)

  if route
    route.params(request).each do |name, value|
      request.update_param(name, value)
    end
    route.klass.call(request.env)
  else
    Wouter::Util.not_found
  end
end

Private Instance Methods

find_route(request) click to toggle source
# File lib/wouter/wrapper.rb, line 30
def find_route(request)
  @routes.find do |route|
    route.match?(request)
  end
end