Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.util.Map.Entry
import com.typesafe.config.{ConfigFactory, ConfigObject, ConfigValue}
import scala.collection.JavaConverters._
import scala.util.Properties
class Configuration(fileNameOption: Option[String] = None) {
val config = fileNameOption.fold(ifEmpty = ConfigFactory.load())(file => ConfigFactory.load(file) )
def envOrElseConfig(name: String): String = {
Properties.envOrElse(
name.toUpperCase.replaceAll("""\.""", "_"), config.getString(name)
)
}
def getMap(name: String): Map[String, String] ={
val list : Iterable[ConfigObject] = config.getObjectList(name).asScala
(for {
item : ConfigObject <- list
entry : Entry[String, ConfigValue] <- item.entrySet().asScala
key = entry.getKey
value = entry.getValue.unwrapped().toString
} yield (key, value)).toMap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.