lib/popcorn: extract Router::build_route private service
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 23 May 2016 20:49:11 +0000 (16:49 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 25 May 2016 03:37:13 +0000 (23:37 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

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.