Skip to content

Instantly share code, notes, and snippets.

@jesusjavierdediego
Created June 11, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusjavierdediego/eed5e1709a01ba885b06175b1740573c to your computer and use it in GitHub Desktop.
Save jesusjavierdediego/eed5e1709a01ba885b06175b1740573c to your computer and use it in GitHub Desktop.
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