org.http4k.config.MapEnvironment.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-config Show documentation
Show all versions of http4k-config Show documentation
Machinery for configuring Http4k apps in a typesafe way
The newest version!
package org.http4k.config
import org.http4k.lens.LensExtractor
import java.io.Reader
import java.util.Properties
class MapEnvironment private constructor(
private val contents: Map,
override val separator: String = ","
) : Environment {
override operator fun get(key: LensExtractor) = key(this)
override operator fun get(key: String): String? = contents[key.convertFromKey()]
override operator fun set(key: String, value: String) =
MapEnvironment(contents + (key.convertFromKey() to value), separator)
override fun minus(key: String): Environment = MapEnvironment(contents - key.convertFromKey(), separator)
override fun keys() = contents.keys
companion object {
fun from(properties: Properties, separator: String = ","): Environment = MapEnvironment(
properties.entries
.fold(emptyMap()) { acc, (k, v) -> acc + (k.toString().convertFromKey() to v.toString()) }, separator
)
fun from(reader: Reader, separator: String = ","): Environment =
from(Properties().apply { load(reader) }, separator)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy