Class: Takagi::Router::RouteMatcher
- Inherits:
-
Object
- Object
- Takagi::Router::RouteMatcher
- Defined in:
- lib/takagi/router/route_matcher.rb
Overview
Handles dynamic route matching with parameter extraction.
Extracted from Router to follow Single Responsibility Principle. Manages matching URL patterns with dynamic segments (e.g., /users/:id) and extracting parameters from matched routes.
Instance Method Summary collapse
-
#initialize(logger) ⇒ RouteMatcher
constructor
A new instance of RouteMatcher.
-
#match(routes, method, path) ⇒ Array(RouteEntry, Hash), Array(nil, Hash)
Matches dynamic routes that contain parameters (e.g., ‘/users/:id`).
Constructor Details
#initialize(logger) ⇒ RouteMatcher
Returns a new instance of RouteMatcher.
12 13 14 |
# File 'lib/takagi/router/route_matcher.rb', line 12 def initialize(logger) @logger = logger end |
Instance Method Details
#match(routes, method, path) ⇒ Array(RouteEntry, Hash), Array(nil, Hash)
Matches dynamic routes that contain parameters (e.g., ‘/users/:id`)
22 23 24 25 26 27 28 |
# File 'lib/takagi/router/route_matcher.rb', line 22 def match(routes, method, path) matched_route = locate_dynamic_route(routes, method, path) return matched_route if matched_route @logger.debug 'No route matched!' [nil, {}] end |