Class: Nile::Router
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #add_route(verb, url, block) ⇒ Object
- #find_route(verb, url) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize ⇒ Router
11 12 13 |
# File 'lib/nile/framework.rb', line 11 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
9 10 11 |
# File 'lib/nile/framework.rb', line 9 def routes @routes end |
Instance Method Details
#add_route(verb, url, block) ⇒ Object
15 16 17 |
# File 'lib/nile/framework.rb', line 15 def add_route(verb, url, block) @routes << {:verb => verb, :url => url, :cb => block} end |
#find_route(verb, url) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/nile/framework.rb', line 19 def find_route verb, url @routes.each do |route| if route[:url] == url && route[:verb] == verb return route end end return {:cb => Proc.new { [404, {}, ["Not found"]] } } end |