class Rack::Routing::Router
Constants
- VALID_HTTP_METHODS
Public Class Methods
for(env)
click to toggle source
# File lib/rack/router.rb, line 7 def for env http_method = env[ 'REQUEST_METHOD' ].to_sym raise 'Invalid HTTP method' unless VALID_HTTP_METHODS.include?( http_method ) parts = [ http_method ] + env[ 'PATH_INFO' ].split( '/' ).reject{| p | String.blank?( p )} matched_route = ROUTES.find do |route| route.match?( parts ) end return { method: :not_found, params:{} } unless matched_route params = matched_route.params_for( parts ) { method: matched_route.routing_method, params:params } end
load_routes()
click to toggle source
# File lib/rack/router.rb, line 26 def load_routes lines = ::File.read( ROUTES_FILE ) .split( "\n" ) .reject{| l | String.blank?( l )} .reject{| l | l.match /\A\s*#/ } lines.map do |line| Route.new( line ) end end