From 93cfdf0dcf6404eb636037fbb59fbff8389a434a Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 2 Jun 2018 00:07:39 +0200 Subject: Generate automatic routes names. --- .../pl/treksoft/kvision/remote/ServiceManager.kt | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/main') diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt index df3245c3..fc464154 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt @@ -26,94 +26,101 @@ import kotlinx.coroutines.experimental.Deferred /** * Multiplatform service manager. */ -actual open class ServiceManager actual constructor(service: T?) { +actual open class ServiceManager actual constructor(service: T) { protected val calls: MutableMap> = mutableMapOf() + var counter: Int = 0 /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, - noinline function: T.(Request?) -> Deferred, method: RpcHttpMethod, prefix: String + noinline function: T.(Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, - noinline function: T.(PAR, Request?) -> Deferred, method: RpcHttpMethod, prefix: String + noinline function: T.(PAR, Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, - noinline function: T.(PAR1, PAR2, Request?) -> Deferred, method: RpcHttpMethod, prefix: String + noinline function: T.(PAR1, PAR2, Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred, method: RpcHttpMethod, prefix: String + noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred, method: RpcHttpMethod, prefix: String + noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** * Binds a given route with a function of the receiver. - * @param route a route * @param function a function of the receiver + * @param route a route * @param method a HTTP method * @param prefix an URL address prefix */ protected actual inline fun bind( - route: String, noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred, + route: String?, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = Pair("$prefix$route", method) + val routeDef = if (route != null) route else "route${this::class.simpleName}${counter++}" + calls[function.toString()] = Pair("$prefix$routeDef", method) } /** @@ -127,4 +134,4 @@ actual open class ServiceManager actual constructor(service: T?) { * Returns the map of defined paths. */ actual fun getCalls(): Map> = calls -} +} \ No newline at end of file -- cgit