Class: Flame::Router
- Inherits:
-
Object
- Object
- Flame::Router
- Defined in:
- lib/flame/router.rb
Overview
Router class for routing
Defined Under Namespace
Classes: RouteRefine
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #add_controller(ctrl, path, block = nil) ⇒ Object
-
#find_route(attrs) ⇒ Object
Find route by any attributes.
-
#initialize ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
9 10 11 |
# File 'lib/flame/router.rb', line 9 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
7 8 9 |
# File 'lib/flame/router.rb', line 7 def routes @routes end |
Instance Method Details
#add_controller(ctrl, path, block = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/flame/router.rb', line 13 def add_controller(ctrl, path, block = nil) ## TODO: Add Regexp paths ## TODO: Add `before` and `after` methods ## Add routes from controller to glob array ctrl_routes = RouteRefine.new(ctrl, path, block).routes ActionsValidator.new(ctrl_routes, ctrl).valid? routes.concat(ctrl_routes) end |
#find_route(attrs) ⇒ Object
Find route by any attributes
24 25 26 |
# File 'lib/flame/router.rb', line 24 def find_route(attrs) routes.find { |route| route.compare_attributes(attrs) } end |