1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ import reactor.core.publisher.Mono
50
50
* @see RouterFunctionDsl
51
51
* @since 5.0
52
52
*/
53
- fun router (routes : RouterFunctionDsl .() -> Unit ) = RouterFunctionDsl (). apply ( routes).router ()
53
+ fun router (routes : RouterFunctionDsl .() -> Unit ) = RouterFunctionDsl (routes).invoke ()
54
54
55
55
/* *
56
56
* Provide a [RouterFunction] Kotlin DSL in order to be able to write idiomatic Kotlin code.
@@ -60,7 +60,7 @@ fun router(routes: RouterFunctionDsl.() -> Unit) = RouterFunctionDsl().apply(rou
60
60
* @since 5.0
61
61
* @see <a href="https://youtrack.jetbrains.com/issue/KT-15667">Kotlin issue about supporting ::foo for member functions</a>
62
62
*/
63
- open class RouterFunctionDsl {
63
+ open class RouterFunctionDsl ( private val init : RouterFunctionDsl .() -> Unit ) : () -> RouterFunction<ServerResponse> {
64
64
65
65
private val routes = mutableListOf<RouterFunction <ServerResponse >>()
66
66
@@ -131,8 +131,8 @@ open class RouterFunctionDsl {
131
131
* common path (prefix), header, or other request predicate.
132
132
* @see RouterFunctions.nest
133
133
*/
134
- fun RequestPredicate.nest (r : RouterFunctionDsl .() -> Unit ) {
135
- routes + = RouterFunctions .nest(this , RouterFunctionDsl (). apply (r).router ())
134
+ fun RequestPredicate.nest (init : RouterFunctionDsl .() -> Unit ) {
135
+ routes + = RouterFunctions .nest(this , RouterFunctionDsl (init ).invoke ())
136
136
}
137
137
138
138
/* *
@@ -143,8 +143,8 @@ open class RouterFunctionDsl {
143
143
* @see RouterFunctions.nest
144
144
* @see RequestPredicates.path
145
145
*/
146
- fun String.nest (r : RouterFunctionDsl .() -> Unit ) {
147
- routes + = RouterFunctions .nest(path(this ), RouterFunctionDsl (). apply (r).router ())
146
+ fun String.nest (init : RouterFunctionDsl .() -> Unit ) {
147
+ routes + = RouterFunctions .nest(path(this ), RouterFunctionDsl (init ).invoke ())
148
148
}
149
149
150
150
/* *
@@ -423,9 +423,11 @@ open class RouterFunctionDsl {
423
423
424
424
/* *
425
425
* Return a composed routing function created from all the registered routes.
426
+ * @since 5.1
426
427
*/
427
- internal fun router (): RouterFunction <ServerResponse > {
428
+ override fun invoke (): RouterFunction <ServerResponse > {
429
+ init ()
428
430
return routes.reduce(RouterFunction <ServerResponse >::and )
429
431
}
430
432
431
- }
433
+ }
0 commit comments