Class: Wouter::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/wouter/wrapper.rb

Overview

‘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.

Instance Method Summary collapse

Constructor Details

#initialize(routes:, config: {}) ⇒ Wrapper

Returns a new instance of Wrapper.



8
9
10
11
# File 'lib/wouter/wrapper.rb', line 8

def initialize(routes:, config: {})
  @routes = routes
  @config = config
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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