Class: Restfulness::Router
- Inherits:
-
Object
- Object
- Restfulness::Router
- Defined in:
- lib/restfulness/router.rb
Instance Attribute Summary collapse
-
#current_scope ⇒ Object
Returns the value of attribute current_scope.
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #add(*args, &block) ⇒ Object
-
#initialize(&block) ⇒ Router
constructor
A new instance of Router.
- #route_for(path) ⇒ Object
- #scope(*args, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Router
Returns a new instance of Router.
8 9 10 11 12 |
# File 'lib/restfulness/router.rb', line 8 def initialize(&block) self.routes = [] self.current_scope = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#current_scope ⇒ Object
Returns the value of attribute current_scope
6 7 8 |
# File 'lib/restfulness/router.rb', line 6 def current_scope @current_scope end |
#routes ⇒ Object
Returns the value of attribute routes
6 7 8 |
# File 'lib/restfulness/router.rb', line 6 def routes @routes end |
Instance Method Details
#add(*args, &block) ⇒ Object
14 15 16 17 18 |
# 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) ⇒ Object
27 28 29 30 31 32 33 |
# 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) ⇒ Object
20 21 22 23 24 25 |
# 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 |