lib/popcorn: extract Router::build_route private service
[nit.git] / lib / popcorn / pop_handlers.nit
index 2c85e15..2ce4755 100644 (file)
@@ -311,14 +311,7 @@ class Router
        #
        # Route paths are matched in registration order.
        fun use(path: String, handler: Handler) do
-               var route
-               if handler isa Router or handler isa StaticHandler then
-                       route = new AppGlobRoute(path)
-               else if path.has_suffix("*") then
-                       route = new AppGlobRoute(path)
-               else
-                       route = new AppParamRoute(path)
-               end
+               var route = build_route(handler, path)
                handlers[route] = handler
        end
 
@@ -329,6 +322,16 @@ class Router
                        if res.sent then break
                end
        end
+
+       private fun build_route(handler: Handler, path: String): AppRoute do
+               if handler isa Router or handler isa StaticHandler then
+                       return new AppGlobRoute(path)
+               else if path.has_suffix("*") then
+                       return new AppGlobRoute(path)
+               else
+                       return new AppParamRoute(path)
+               end
+       end
 end
 
 # Popcorn application.