Class: Flame::Router
- Inherits:
-
Object
- Object
- Flame::Router
- Defined in:
- lib/flame/router.rb,
lib/flame/router/route.rb
Overview
Router class for routing
Defined Under Namespace
Classes: Route, RouteRefine
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#add_controller(ctrl, path = nil) { ... } ⇒ Object
Add the controller with it’s methods to routes.
-
#find_nearest_route(path) ⇒ Flame::Route?
Find the nearest route by path.
-
#find_route(attrs) ⇒ Flame::Route?
Find route by any attributes.
-
#initialize(app) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(app) ⇒ Router
Returns a new instance of Router.
10 11 12 13 |
# File 'lib/flame/router.rb', line 10 def initialize(app) @app = app @routes = [] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/flame/router.rb', line 8 def app @app end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
8 9 10 |
# File 'lib/flame/router.rb', line 8 def routes @routes end |
Instance Method Details
#add_controller(ctrl, path = nil) { ... } ⇒ Object
Add the controller with it’s methods to routes
19 20 21 22 23 24 25 |
# File 'lib/flame/router.rb', line 19 def add_controller(ctrl, path = nil, &block) ## @todo Add Regexp paths ## Add routes from controller to glob array route_refine = RouteRefine.new(self, ctrl, path, block) concat_routes(route_refine) end |
#find_nearest_route(path) ⇒ Flame::Route?
Find the nearest route by path
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flame/router.rb', line 38 def find_nearest_route(path) path = Flame::Path.new(path) if path.is_a? String path_parts = path.parts.dup while path_parts.size >= 0 route = find_route path: Flame::Path.new(*path_parts) break if route || path_parts.empty? path_parts.pop end route end |
#find_route(attrs) ⇒ Flame::Route?
Find route by any attributes
30 31 32 33 |
# File 'lib/flame/router.rb', line 30 def find_route(attrs) route = routes.find { |r| r.compare_attributes(attrs) } route.dup if route end |