Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

ciris-hocon scaladex-badge ci-badge gitter-badge

ciris-hocon provides a HOCON configuration source for Ciris configuration loading library.

The implementation of this library was created by following the excellent Ciris documentation.

Setup

Add the dependency to your project build settings:

libraryDependencies += "lt.dvim.ciris-hocon" %% "ciris-hocon" % "0.2.1"

Or a snapshot from a snapshot repository.

version scala ciris
0.1 2.12 0.12.1
0.2.1 2.13 0.13.0-RC1
upstream 2.12, 2.13 1.0.x

Example usage

This library provides configuration sources as well as decoders from ConfigValue values.

import ciris._
import lt.dvim.ciris.Hocon._
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
import java.time.Period

val config = ConfigFactory.parseString("""
    |rate {
    |  elements = 2
    |  burst-duration = 100 millis
    |  check-interval = 2 weeks
    |}
  """.stripMargin)

case class Rate(elements: Int, burstDuration: FiniteDuration, checkInterval: Period)

val hocon = hoconAt(config)("rate")
val rate = loadConfig(
  hocon[Int]("elements"),
  hocon[FiniteDuration]("burst-duration"),
  hocon[Period]("check-interval")
)(Rate.apply).orThrow()

rate.burstDuration shouldBe 100.millis
rate.checkInterval shouldBe Period.ofWeeks(2)