Created
June 11, 2018 20:18
-
-
Save jesusjavierdediego/eed5e1709a01ba885b06175b1740573c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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