class Router

Attributes

routes[R]

Public Class Methods

new() click to toggle source
# File lib/laris/router.rb, line 26
def initialize
  @routes = []
end

Public Instance Methods

add_route(pattern, http_method, controller_class, action_name) click to toggle source
# File lib/laris/router.rb, line 30
def add_route(pattern, http_method, controller_class, action_name)
  @routes << Route.new(pattern, http_method, controller_class, action_name)
end
draw(&proc) click to toggle source
# File lib/laris/router.rb, line 34
def draw(&proc)
  instance_eval(&proc)
end
match(req) click to toggle source
# File lib/laris/router.rb, line 44
def match(req)
  @routes.find { |route| route.matches?(req) }
end
run(req, res) click to toggle source
# File lib/laris/router.rb, line 48
def run(req, res)
  route = match(req)

  if route.nil?
    res.status = 404

    res.write("Oops! The requested URL #{req.path} was not not found!")
  else
    route.run(req, res)
  end
end