class RackStep::Router
Attributes
Will store all the possible routes. By default it’s empty and should be populated by the application (RackStep
will add a 404 route, the others should be added by the user).
Public Class Methods
Public Instance Methods
Source
# File lib/router.rb, line 22 def add_route(verb, path, controller) path = path[1..-1] if path[0] == '/' # Ignoring the first char if path starts with '/'. route = Route.new(verb, path, controller) routes[route.id] = route end
Source
# File lib/router.rb, line 46 def add_route_for_all_verbs(path, controller) add_route('GET', path, controller) add_route('POST', path, controller) add_route('DELETE', path, controller) add_route('PUT', path, controller) end
Adds new routes to the application, one for each possible http verb (GET, POST, DELETE and PUT).
Source
# File lib/router.rb, line 30 def find_route_for(path, verb) # Ignoring the first char if path starts with '/'. This way the path of # 'http//localhost/' will be the same of 'http://localhost' (both will # be empty strings). path = path[1..-1] if path[0] == '/' route_id = verb + path route = routes[route_id] # If no route was found, set it to 'notfound' route (maintaining the # original verb). route = routes["#{verb}notfound"] if route == nil return route end
Given a request, will parse it’s path to find what it the apropriate controller to respond it.