abstract class Config extends AnyRef
Type class based wrapper for Typesafe Config.
Supported types:
- Natively by Typesafe Config:
Boolean
Double
Int
Long
String
java.time.Duration
- Mapped (usually from strings converted using a factory method from the respective class):
scala.concurrent.duration.FiniteDuration
scala.math.BigDecimal
scala.math.BigInt
java.time.LocalDate
java.time.LocalDateTime
java.time.LocalTime
java.time.MonthDay
java.time.OffsetDateTime
java.time.Period
java.time.Year
java.time.YearMonth
java.time.ZonedDateTime
java.time.ZoneId
java.util.Locale
java.util.UUID
- Source
- Config.scala
import scail.commons.util.Config import scail.commons.util.Config.ConfigOps import com.typesafe.config.{Config => TypesafeConfig} class MyConfig(underlying: TypesafeConfig) extends Config(underlying) { object Db extends Config('db) { // Throws an exception at construction time if the setting is missing, as recommended by // https://github.com/typesafehub/config#schemas-and-validation val url: String = 'url.required // equivalent to config.getString("db.url") } val a = 'a.required[Boolean] val b: Double = 'b.required val c = 'c.optional[Duration] // c: Option[Duration] val d: Option[Int] = 'd.optional val e = 'e orElse 42L // e: Long val f = 'f.orBlank // f: String val g = 'g.orFalse // g: Boolean val h = 'h.orTrue // h: Boolean val i = 'i.orZero // i: Int val r = 'r.required[Seq[FiniteDuration]] val s: Seq[BigDecimal] = 's.required val t = 't.optional[Seq[LocalDateTime]] // t: Option[Seq[LocalDateTime]] val u: Option[Seq[Year]] = 'u.optional val v = 'v.orEmpty[Locale] // v: Seq[Locale] val w: Seq[UUID] = 'w.orEmpty val x: String = Symbol("a.very-complicated:key_name!").required }
Custom
Reader
s are easily created by mapping on existing readers: , import scail.commons.util.Config.Reader case class Age(age: Int) case class Name(name: String) implicit val ageReader = Reader.int.map(Age.apply) implicit val nameReader = Reader.string.map(Name.apply) val myName: Name = 'myName.required val myAge = 'myAge.optional[Age] val friendNames: Seq[Name] = 'friendNames.orEmpty
Creating a custom
Reader
for composite data types is also straightforward: , case class Person(name: Name, age: Age, friends: Seq[Person]) object Person { implicit val personReader = Reader { implicit config => Person('name.required, 'age.required, 'friends.required) } }
Examples:
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- Config
- AnyRef
- Any
Implicitly
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
Visibility
- Public
- All
Instance Constructors
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (Config, B)
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- def ensuring(cond: (Config) ⇒ Boolean, msg: ⇒ Any): Config
- def ensuring(cond: (Config) ⇒ Boolean): Config
- def ensuring(cond: Boolean, msg: ⇒ Any): Config
- def ensuring(cond: Boolean): Config
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
path(key: Key): String
- Attributes
- protected
-
implicit
val
self: Config
- Attributes
- protected
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- def →[B](y: B): (Config, B)