class Router
Attributes
routes[R]
Public Class Methods
new()
click to toggle source
# File lib/matrack/router.rb, line 4 def initialize @routes = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
draw(&block)
click to toggle source
# File lib/matrack/router.rb, line 8 def draw(&block) instance_eval(&block) end
root(root_path)
click to toggle source
# File lib/matrack/router.rb, line 12 def root(root_path) get "/", root_path end
route_for(env)
click to toggle source
# File lib/matrack/router.rb, line 27 def route_for(env) path = env["PATH_INFO"] verb = env["REQUEST_METHOD"].downcase.to_sym route_info = routes[verb].detect do |route| route.first == path || route.first == path.sub("/", "") end Route.new(route_info) if route_info end
Private Instance Methods
case_parser(str)
click to toggle source
# File lib/matrack/router.rb, line 38 def case_parser(str) matclass, method = str.split("#") { matclass: matclass.to_camel_case, method: method.to_snake_case } end