Configs

Derivation of Configs instances.

Make sure to familiarize yourself with creating structible instances before looking at the examples below.

Dependency

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

Example

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

object ConfigsExample {

  final case class UserId private (value: Long) extends AnyVal

  object UserId {

    private val structible: Structible[Long, UserId] = Structible.structible(new UserId(_), _.value, c >= 0)

    implicit val configsForUserId: Configs[UserId] = structible.toConfigs

    def apply(value: Long): UserId = structible.construct(value)
  }

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

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