Class: Chespirito::RouteConstraintChecker
- Inherits:
-
Object
- Object
- Chespirito::RouteConstraintChecker
- Defined in:
- lib/chespirito/routes/route_constraint_checker.rb
Instance Method Summary collapse
- #extract_params(route) ⇒ Object
-
#initialize(request) ⇒ RouteConstraintChecker
constructor
A new instance of RouteConstraintChecker.
- #match_route?(route) ⇒ Boolean
- #request_constraints(route) ⇒ Object
- #request_parts ⇒ Object
- #route_constraints(route) ⇒ Object
- #route_parts(route) ⇒ Object
Constructor Details
#initialize(request) ⇒ RouteConstraintChecker
Returns a new instance of RouteConstraintChecker.
7 8 9 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 7 def initialize(request) @request = request end |
Instance Method Details
#extract_params(route) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 18 def extract_params(route) return {} unless route.respond_to?(:path) return {} unless match_route?(route) route_constraints(route) .zip(request_constraints(route)) .to_h end |
#match_route?(route) ⇒ Boolean
11 12 13 14 15 16 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 11 def match_route?(route) return false unless route.respond_to?(:path) return false if route_constraints(route).empty? route_constraints(route).size == request_constraints(route).size end |
#request_constraints(route) ⇒ Object
28 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 28 def request_constraints(route) = request_parts - route_parts(route) |
#request_parts ⇒ Object
31 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 31 def request_parts = RouteUtils.words(@request.path) |
#route_constraints(route) ⇒ Object
27 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 27 def route_constraints(route) = RouteUtils.constraints(route.path) |
#route_parts(route) ⇒ Object
30 |
# File 'lib/chespirito/routes/route_constraint_checker.rb', line 30 def route_parts(route) = RouteUtils.parts(route.path) |