Class: MVCLI::Router
- Inherits:
-
Object
- Object
- MVCLI::Router
- Defined in:
- lib/mvcli/router.rb,
lib/mvcli/router/pattern.rb
Defined Under Namespace
Classes: DSL, Macro, Pattern, Route, RoutingError
Instance Attribute Summary collapse
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #call(command) ⇒ Object (also: #[])
-
#initialize ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
13 14 15 16 |
# File 'lib/mvcli/router.rb', line 13 def initialize @routes = [] @macros = [] end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
11 12 13 |
# File 'lib/mvcli/router.rb', line 11 def macros @macros end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
10 11 12 |
# File 'lib/mvcli/router.rb', line 10 def routes @routes end |
Instance Method Details
#call(command) ⇒ Object Also known as: []
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mvcli/router.rb', line 18 def call(command) argv = @macros.reduce(command.argv) do |args, macro| macro. args end @routes.each do |route| if action = route.match(argv) return action end end fail RoutingError, "no route matches '#{command.argv.join ' '}'" end |