Class: Yuriita::Router
- Inherits:
-
Object
- Object
- Yuriita::Router
- Defined in:
- lib/yuriita/router.rb
Instance Method Summary collapse
- #append_route(collection, matcher, to:) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #match_for(input) ⇒ Object
- #route(input, relation) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
3 4 5 |
# File 'lib/yuriita/router.rb', line 3 def initialize @routes = [] end |
Instance Method Details
#append_route(collection, matcher, to:) ⇒ Object
7 8 9 |
# File 'lib/yuriita/router.rb', line 7 def append_route(collection, matcher, to:) routes.append Route.new(collection, matcher, to) end |
#match_for(input) ⇒ Object
18 19 20 |
# File 'lib/yuriita/router.rb', line 18 def match_for(input) routes.detect { |route| route.match?(input) } end |
#route(input, relation) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/yuriita/router.rb', line 11 def route(input, relation) if route = match_for(input) collection = route.collection collection.dispatch(route.action, input, relation) end end |