Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2m/ciris-hocon
Ciris Source for Hocon file format
https://github.com/2m/ciris-hocon
Last synced: 22 days ago
JSON representation
Ciris Source for Hocon file format
- Host: GitHub
- URL: https://github.com/2m/ciris-hocon
- Owner: 2m
- License: apache-2.0
- Created: 2019-01-13T07:59:58.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T13:24:23.000Z (about 2 months ago)
- Last Synced: 2024-09-17T15:47:41.509Z (about 2 months ago)
- Language: Scala
- Homepage:
- Size: 515 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [ciris-hocon][] [![scaladex-badge][]][scaladex] [![ci-badge][]][ci] [![gitter-badge][]][gitter]
[ciris-hocon]: https://github.com/2m/ciris-hocon
[scaladex]: https://index.scala-lang.org/2m/ciris-hocon
[scaladex-badge]: https://index.scala-lang.org/2m/ciris-hocon/latest.svg
[ci]: https://github.com/2m/ciris-hocon/actions
[ci-badge]: https://github.com/2m/ciris-hocon/workflows/ci/badge.svg
[gitter]: https://gitter.im/vlovgr/ciris
[gitter-badge]: https://badges.gitter.im/vlovgr/ciris.svg`ciris-hocon` provides a [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) configuration source for [Ciris](https://cir.is/) configuration loading library.
The implementation of this library was created by following the excellent [Ciris documentation](https://github.com/vlovgr/ciris/blob/v2.0.0-RC3/docs/src/main/mdoc/configurations.md#sources).
## Setup
Add the dependency to your project build settings:
```sbt
libraryDependencies += "lt.dvim.ciris-hocon" %% "ciris-hocon" % "1.2.0"
```Or a snapshot from a [snapshot repository](https://oss.sonatype.org/content/repositories/snapshots/lt/dvim/ciris-hocon/).
| version | scala | ciris |
|------------|-------------|------------|
| 0.1 | 2.12 | 0.12.1 |
| 0.2.1 | 2.13 | 0.13.0-RC1 |
| 1.0.x | 2.13, 3 | 2.x.x |
| 1.1.x | 2.13, 3 | 3.x.x |## Example usage
This library provides configuration sources as well as decoders from [`ConfigValue`](https://lightbend.github.io/config/latest/api/?com/typesafe/config/ConfigValue.html) values.
```scala
import java.time.Period
import scala.concurrent.duration._import cats.effect.IO
import cats.implicits._
import com.typesafe.config.ConfigFactoryimport lt.dvim.ciris.Hocon._
val config = ConfigFactory.parseString("""
|rate {
| elements = 2
| burst-duration = 100 millis
| check-interval = 2 weeks
| values = [ first, second ]
|}
""".stripMargin)case class Rate(
elements: Int,
burstDuration: FiniteDuration,
checkInterval: Period,
values: List[String]
)val hocon = hoconAt(config)("rate")
(
hocon("elements").as[Int],
hocon("burst-duration").as[FiniteDuration],
hocon("check-interval").as[Period],
hocon("values").as[List[String]]
).parMapN(Rate.apply).load[IO].map { rate =>
assertEquals(rate.burstDuration, 100.millis)
assertEquals(rate.checkInterval, Period.ofWeeks(2))
}
```