class Flame::Router
Router
class for routing
Attributes
app[R]
routes[R]
Public Class Methods
new(app)
click to toggle source
# File lib/flame/router.rb, line 10 def initialize(app) @app = app @routes = [] end
Public Instance Methods
add_controller(ctrl, path = nil, &block)
click to toggle source
Add the controller with it's methods to routes @param ctrl [Flame::Controller] class of the controller which will be added @param path [String, nil] root path for controller's methods @yield block for routes refine
# 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)
click to toggle source
Find the nearest route by path @param path [Flame::Path] path for route finding @return [Flame::Route, nil] return the found nearest route or `nil`
# 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)
click to toggle source
Find route by any attributes @param attrs [Hash] attributes for comparing @return [Flame::Route, nil] return the found route, otherwise `nil`
# File lib/flame/router.rb, line 30 def find_route(attrs) route = routes.find { |r| r.compare_attributes(attrs) } route.dup if route end
Private Instance Methods
concat_routes(route_refine)
click to toggle source
Add `RouteRefine` routes to the routes of `Flame::Router` @param route_refine [Flame::Router::RouteRefine] `RouteRefine` with routes
# File lib/flame/router.rb, line 53 def concat_routes(route_refine) routes.concat(route_refine.routes) end