Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Shortcuts for configuring Play2 Applications in scala
package utils
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration._
import play.api.Application
import collection.JavaConversions._
object ConfigString {
implicit class ConfigStr(s: String) {
def configOrElse(default: FiniteDuration)(implicit app: Application): FiniteDuration =
app.configuration.getMilliseconds(s).map(_ milliseconds).getOrElse(default)
def configOrElse(default: Long)(implicit app: Application): Long =
app.configuration.getMilliseconds(s).getOrElse(default)
def configOrElse(default: Double)(implicit app: Application): Double =
app.configuration.getDouble(s).getOrElse(default)
def configOrElse(default: String)(implicit app: Application): String =
app.configuration.getString(s).getOrElse(default)
def configOrElse(default: Boolean)(implicit app: Application): Boolean =
app.configuration.getBoolean(s).getOrElse(default)
def configOrElse(default: Seq[String])(implicit app: Application): Seq[String] =
app.configuration.getStringList(s).map(_.toSeq).getOrElse(default)
}
}
Owner

check out some explanations on coderwall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment