Configs

Derivation of Configs instances.

Dependency

sbt
libraryDependencies += "com.github.cerst" % "structible-configs" % "0.4.0"
Maven
<dependency>
  <groupId>com.github.cerst</groupId>
  <artifactId>structible-configs</artifactId>
  <version>0.4.0</version>
</dependency>
Gradle
dependencies {
  compile group: 'com.github.cerst', name: 'structible-configs', version: '0.4.0'
}

Example

import com.github.cerst.structible.configs.ops._
import com.github.cerst.structible.core.Structible
import com.typesafe.config.Config
import configs._
import configs.syntax._

object ConfigsExample {

  final case class PersonId(value: Long) {
    require(value >= 0, s"PersonId must be non-negative (got: '$value')")
  }

  object PersonId {

    // you can also pass-in 'construct' functions returning Either[String, A], Option[A] or Try[A]
    private val structible: Structible[Long, PersonId] = Structible.structible(PersonId.apply, _.value)

    implicit val configsForPersonId: Configs[PersonId] = structible.toConfigs
  }

  def readFromConfig(config: Config, path: String): Result[PersonId] = {
    config.get[PersonId](path)
  }

}
The source code for this page can be found here.