11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ import reactor.core.publisher.Mono
5050 * @see RouterFunctionDsl
5151 * @since 5.0
5252 */
53- fun router (routes : RouterFunctionDsl .() -> Unit ) = RouterFunctionDsl (). apply ( routes).router ()
53+ fun router (routes : RouterFunctionDsl .() -> Unit ) = RouterFunctionDsl (routes).invoke ()
5454
5555/* *
5656 * 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
6060 * @since 5.0
6161 * @see <a href="https://youtrack.jetbrains.com/issue/KT-15667">Kotlin issue about supporting ::foo for member functions</a>
6262 */
63- open class RouterFunctionDsl {
63+ open class RouterFunctionDsl ( private val init : RouterFunctionDsl .() -> Unit ) : () -> RouterFunction<ServerResponse> {
6464
6565 private val routes = mutableListOf<RouterFunction <ServerResponse >>()
6666
@@ -131,8 +131,8 @@ open class RouterFunctionDsl {
131131 * common path (prefix), header, or other request predicate.
132132 * @see RouterFunctions.nest
133133 */
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 ())
136136 }
137137
138138 /* *
@@ -143,8 +143,8 @@ open class RouterFunctionDsl {
143143 * @see RouterFunctions.nest
144144 * @see RequestPredicates.path
145145 */
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 ())
148148 }
149149
150150 /* *
@@ -423,9 +423,11 @@ open class RouterFunctionDsl {
423423
424424 /* *
425425 * Return a composed routing function created from all the registered routes.
426+ * @since 5.1
426427 */
427- internal fun router (): RouterFunction <ServerResponse > {
428+ override fun invoke (): RouterFunction <ServerResponse > {
429+ init ()
428430 return routes.reduce(RouterFunction <ServerResponse >::and )
429431 }
430432
431- }
433+ }
0 commit comments