Class: Mycommands::Router
- Inherits:
-
Object
- Object
- Mycommands::Router
- Defined in:
- lib/mycommands/router.rb
Instance Method Summary collapse
- #add_route(route) ⇒ Object
- #clear_routes ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #route(input) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
3 4 5 6 |
# File 'lib/mycommands/router.rb', line 3 def initialize @routes = [] @choice = 1 end |
Instance Method Details
#add_route(route) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/mycommands/router.rb', line 8 def add_route route if route[:match].nil? route.merge!(:match => @choice.to_s) @choice += 1 end @routes.push route return @choice - 1 end |
#clear_routes ⇒ Object
17 18 19 20 |
# File 'lib/mycommands/router.rb', line 17 def clear_routes @routes = [] @choice = 1 end |
#route(input) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/mycommands/router.rb', line 22 def route input @routes.each do |route| if input.match route[:match] return route[:controller], route[:action], route[:input].nil? ? input : route[:input] end end false end |