class Restfulness::Router
Attributes
current_scope[RW]
routes[RW]
Public Class Methods
new(&block)
click to toggle source
# File lib/restfulness/router.rb, line 8 def initialize(&block) self.routes = [] self.current_scope = [] instance_eval(&block) if block_given? end
Public Instance Methods
add(*args, &block)
click to toggle source
# File lib/restfulness/router.rb, line 14 def add(*args, &block) # Do we need to pretend we've been given a scope? scope(*args[0..-2], &block) if block_given? routes << Route.new(*(current_scope + args)) end
route_for(path)
click to toggle source
# File lib/restfulness/router.rb, line 27 def route_for(path) parts = path.gsub(/^\/|\/$/, '').split(/\//) routes.each do |route| return route if route.handles?(parts) end nil end
scope(*args, &block)
click to toggle source
# File lib/restfulness/router.rb, line 20 def scope(*args, &block) old_scope = current_scope self.current_scope += args instance_eval(&block) if block_given? self.current_scope = old_scope end