class TGauge::Router

Attributes

routes[R]

Public Class Methods

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

Public Instance Methods

add_route(pattern, method, controller_class, action_name) click to toggle source

simply adds a new route to the list of routes

# File lib/db/router.rb, line 39
def add_route(pattern, method, controller_class, action_name)
  @routes << Route.new(pattern, method, controller_class, action_name)
end
draw(&proc) click to toggle source

evaluate the proc in the context of the instance for syntactic sugar :)

# File lib/db/router.rb, line 45
def draw(&proc)
  self.instance_eval(&proc)
end
match(req) click to toggle source

should return the route that matches this request

# File lib/db/router.rb, line 58
def match(req)
  @routes.each do |route|
    return route if route.matches?(req)
  end
  nil
end
run(req, res) click to toggle source

either throw 404 or call run on a matched route

# File lib/db/router.rb, line 66
def run(req, res)
  route = match(req)
  if route
    route.run(req, res)
  else
    res.write("Route #{req.path} could not be found.")
    res.status = 404
  end
end