Class: Restfulness::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulness/router.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Router

Returns a new instance of Router.



8
9
10
11
# File 'lib/restfulness/router.rb', line 8

def initialize(&block)
  self.routes = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#routesObject

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) ⇒ Object



13
14
15
# File 'lib/restfulness/router.rb', line 13

def add(*args)
  routes << Route.new(*args)
end

#route_for(path) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/restfulness/router.rb', line 17

def route_for(path)
  parts = path.gsub(/^\/|\/$/, '').split(/\//)
  routes.each do |route|
    return route if route.handles?(parts)
  end
  nil
end