class Rasti::Web::Router
Constants
- NOT_FOUND_PATTERN
- VERBS
Public Instance Methods
all_routes()
click to toggle source
# File lib/rasti/web/router.rb, line 25 def all_routes Hash[routes.map { |m,r| [m, r.map(&:pattern)] }] end
call(env)
click to toggle source
# File lib/rasti/web/router.rb, line 19 def call(env) route = route_for env env[ROUTE_PARAMS] = route.extract_params env['PATH_INFO'] route.call env end
not_found(endpoint=nil, &block)
click to toggle source
# File lib/rasti/web/router.rb, line 15 def not_found(endpoint=nil, &block) @not_found_route = Route.new(NOT_FOUND_PATTERN, endpoint, &block) end
Private Instance Methods
not_found_route()
click to toggle source
# File lib/rasti/web/router.rb, line 39 def not_found_route @not_found_route ||= Route.new NOT_FOUND_PATTERN do |request, response, render| render.status 404, "Not found: #{request.request_method} #{request.path_info}" end end
route_for(env)
click to toggle source
# File lib/rasti/web/router.rb, line 35 def route_for(env) routes[env['REQUEST_METHOD'].upcase].detect { |r| r.match? env['PATH_INFO'] } || not_found_route end
routes()
click to toggle source
# File lib/rasti/web/router.rb, line 31 def routes @routes ||= Hash.new { |h,k| h[k] = [] } end