run.smt.ktest.rest.url.url.kt Maven / Gradle / Ivy
package run.smt.ktest.rest.url
import com.typesafe.config.Config
import run.smt.ktest.config.config
import run.smt.ktest.config.get
import run.smt.ktest.config.fallbackTo
typealias UrlDsl = (U.() -> String) -> String
/**
* Create DSL for URLs based on constructor for UrlProvider
*/
fun createUrlDsl(providerFactory: (Config) -> T): UrlDsl {
val urls: Config = config["urls"]
val url: Config = config["url"]
return createUrlDsl(providerFactory(urls fallbackTo url))
}
/**
* Create DSL for URLs based on UrlProvider
*/
fun createUrlDsl(provider: T): UrlDsl = provider::run
/**
* Source of URLs
*/
interface UrlProvider {
fun param(name: String) = "{$name}"
operator fun String.div(other: String) = this + "/" + other
}