@@ -2,7 +2,7 @@ module Kemal
22 # Router provides modular routing capabilities for Kemal applications.
33 #
44 # It allows grouping routes under a common prefix and applying filters
5- # to specific route groups. Routers can be nested using `namespace` or `group` .
5+ # to specific route groups. Routers can be nested using `namespace`.
66 #
77 # ## Example
88 #
@@ -68,7 +68,7 @@ module Kemal
6868 end
6969
7070 # HTTP method helpers
71- {% for method in %w[get post put patch delete options] % }
71+ {% for method in HTTP_METHODS % }
7272 # Defines a {{ method.id.upcase }} route.
7373 #
7474 # ```
@@ -117,7 +117,7 @@ module Kemal
117117 end
118118
119119 # Method-specific before/after filters
120- {% for method in %w[get post put patch delete options all] % }
120+ {% for method in FILTER_METHODS % }
121121 # Defines a before filter for {{ method.id.upcase }} requests.
122122 def before_ {{ method.id }}(path : String = " *" , & block : HTTP ::Server ::Context - > _)
123123 add_filter(:before , {{ method.upcase }}, path, & block)
@@ -129,7 +129,10 @@ module Kemal
129129 end
130130 {% end % }
131131
132- # Creates a nested namespace/group with the given path prefix.
132+ # Creates a nested namespace/group with the given *path* prefix.
133+ #
134+ # NOTE: The path must start with a `/`.
135+ #
133136 # All routes defined inside the block will be prefixed with the given path.
134137 #
135138 # ```
@@ -149,7 +152,9 @@ module Kemal
149152 @sub_routers << SubRouter .new(path: path, router: sub_router)
150153 end
151154
152- # Mounts another router at the given path prefix.
155+ # Mounts another router at the given *path* prefix.
156+ #
157+ # NOTE: The path must start with a `/`.
153158 #
154159 # ```
155160 # users_router = Kemal::Router.new
@@ -207,7 +212,6 @@ module Kemal
207212 end
208213
209214 # Collect all route paths including sub-routers
210- # :nodoc:
211215 protected def collect_all_route_paths (full_prefix : String ) : Array (Tuple (String , String ))
212216 paths = [] of Tuple (String , String )
213217
@@ -248,7 +252,7 @@ module Kemal
248252
249253 applicable_paths.each do |route_method , route_path |
250254 # Check if filter method matches route method
251- next unless filter.method == " ALL" || filter.method == route_method
255+ next unless filter.method.in?( " ALL" , route_method)
252256
253257 # Use filter's method (ALL or specific) when registering
254258 register_method = filter.method
@@ -284,8 +288,8 @@ module Kemal
284288 end
285289
286290 private def join_paths (a : String , b : String ) : String
287- a = a.chomp(" / " )
288- b = b.lchop(" / " ) if b.starts_with?(" / " )
291+ a = a.chomp('/' )
292+ b = b.lchop('/' ) if b.starts_with?('/' )
289293 return " /#{ b } " if a.empty?
290294 return a if b.empty?
291295 " #{ a } /#{ b } "
0 commit comments