aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/remote
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-06-02 00:07:39 +0200
committerRobert Jaros <rjaros@finn.pl>2018-06-02 00:07:39 +0200
commit93cfdf0dcf6404eb636037fbb59fbff8389a434a (patch)
tree8d25e6a099811e2fd771d49f4b5fb62ceaea9e2e /src/main/kotlin/pl/treksoft/kvision/remote
parent656e823d91301f637feff2edea3920d3625b43c2 (diff)
downloadkvision-93cfdf0dcf6404eb636037fbb59fbff8389a434a.tar.gz
kvision-93cfdf0dcf6404eb636037fbb59fbff8389a434a.tar.bz2
kvision-93cfdf0dcf6404eb636037fbb59fbff8389a434a.zip
Generate automatic routes names.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/remote')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt57
1 files changed, 32 insertions, 25 deletions
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<out T> actual constructor(service: T?) {
+actual open class ServiceManager<out T> actual constructor(service: T) {
protected val calls: MutableMap<String, Pair<String, RpcHttpMethod>> = 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 <reified RET> bind(
- route: String,
- noinline function: T.(Request?) -> Deferred<RET>, method: RpcHttpMethod, prefix: String
+ noinline function: T.(Request?) -> Deferred<RET>,
+ 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 <reified PAR, reified RET> bind(
- route: String,
- noinline function: T.(PAR, Request?) -> Deferred<RET>, method: RpcHttpMethod, prefix: String
+ noinline function: T.(PAR, Request?) -> Deferred<RET>,
+ 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 <reified PAR1, reified PAR2, reified RET> bind(
- route: String,
- noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>, method: RpcHttpMethod, prefix: String
+ noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>,
+ 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 <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
- route: String,
- noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>, method: RpcHttpMethod, prefix: String
+ noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>,
+ 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 <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
- route: String,
- noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>, method: RpcHttpMethod, prefix: String
+ noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>,
+ 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 <reified PAR1, reified PAR2, reified PAR3,
reified PAR4, reified PAR5, reified RET> bind(
- route: String,
noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>,
+ 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<out T> actual constructor(service: T?) {
* Returns the map of defined paths.
*/
actual fun getCalls(): Map<String, Pair<String, RpcHttpMethod>> = calls
-}
+} \ No newline at end of file