Class: MVCLI::Router
- Inherits:
-
Object
- Object
- MVCLI::Router
- Defined in:
- lib/mvcli/router.rb,
lib/mvcli/router/pattern.rb
Defined Under Namespace
Constant Summary collapse
- RoutingError =
Class.new StandardError
- InvalidRoute =
Class.new RoutingError
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(actions = nil) ⇒ Router
constructor
A new instance of Router.
- #match(options) ⇒ Object
Constructor Details
#initialize(actions = nil) ⇒ Router
Returns a new instance of Router.
10 11 12 13 |
# File 'lib/mvcli/router.rb', line 10 def initialize(actions = nil) @actions = actions || Map.new @routes = [] end |
Instance Method Details
#call(command) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/mvcli/router.rb', line 21 def call(command) @routes.each do |route| if match = route.match(command) return match.call command end end fail RoutingError, "no route matches '#{command.argv.join ' '}'" end |