Confide macros

confidemacros

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

io.estatico
ArtifactId

ArtifactId

confide-macros_2.11
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Confide macros
confidemacros
Project URL

Project URL

https://github.com/estatico/confide
Project Organization

Project Organization

io.estatico
Source Code Management

Source Code Management

https://github.com/estatico/confide

Download confide-macros_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/io.estatico/confide-macros_2.11/ -->
<dependency>
    <groupId>io.estatico</groupId>
    <artifactId>confide-macros_2.11</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.estatico/confide-macros_2.11/
implementation 'io.estatico:confide-macros_2.11:0.0.3'
// https://jarcasting.com/artifacts/io.estatico/confide-macros_2.11/
implementation ("io.estatico:confide-macros_2.11:0.0.3")
'io.estatico:confide-macros_2.11:jar:0.0.3'
<dependency org="io.estatico" name="confide-macros_2.11" rev="0.0.3">
  <artifact name="confide-macros_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.estatico', module='confide-macros_2.11', version='0.0.3')
)
libraryDependencies += "io.estatico" % "confide-macros_2.11" % "0.0.3"
[io.estatico/confide-macros_2.11 "0.0.3"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8
io.estatico : confide-core_2.11 jar 0.0.3
com.chuusai : shapeless_2.11 jar 2.3.2
com.typesafe : config jar 1.3.1
org.typelevel : macro-compat_2.11 jar 1.1.1

provided (2)

Group / Artifact Type Version
org.scala-lang : scala-compiler jar 2.11.8
org.scala-lang : scala-reflect jar 2.11.8

test (2)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.13.4
org.scalatest : scalatest_2.11 jar 3.0.0

Project Modules

There are no modules declared in this project.

Confide

Build Status Gitter Maven Central

Automatic configuration decoding for Scala

Setup

SBT

val confideVersion = "0.0.3"

libraryDependencies ++= Seq(
  "io.estatico" %% "confide-core" % confideVersion,
  "io.estatico" %% "confide-macros" % confideVersion,
)

To be able to use the @Conf macro, you'll need the Paradise compiler plugin.

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),

Maven

<properties>
  ...
  <confide.version>0.0.3</confide.version>
</properties>
...
<dependencies>
  ...
  <dependency>
    <groupId>io.estatico</groupId>
    <artifactId>confide-core_${scala.binaryVersion}</artifactId>
    <version>${confide.version}</version>
  </dependency>
  <dependency>
    <groupId>io.estatico</groupId>
    <artifactId>confide-macros_${scala.binaryVersion}</artifactId>
    <version>${confide.version}</version>
  </dependency>
</dependencies>

To be able to use the @Conf macro, you'll need the Paradise compiler plugin.

<pluginManagement>
  ...
  <plugins>
    <plugin>
      <groupId>org.scala-tools</groupId>
      <artifactId>maven-scala-plugin</artifactId>
      <version>${scala.plugin.version}</version>
      <configuration>
        <compilerPlugins>
          <compilerPlugin>
            <groupId>org.scalamacros</groupId>
            <artifactId>paradise_${scala.version}</artifactId>
            <version>2.1.0</version>
          </compilerPlugin>
        </compilerPlugins>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

Usage

Given the configuration file below -

api {
  cache {
    enable: true
    ttl: 5m
  }
  greetings = ["Hello", "Hola", "Bonjour"]
}

We can define the following Scala classes to automatically decode the config for us -

import io.estatico.confide._

@Conf final case class AppConfig(
  api: ApiConf
)

@Conf final case class ApiConf(
  cache: CacheConf,
  greetings: List[String]
)

@Conf final case class CacheConf(
  enable: Boolean,
  ttl: FiniteDuration
)

The case classes are pretty self-evident; they simply define the structure of the config we wish to decode.

The @Conf macro will derive an instance of FromConfObj for the annotated case class. FromConf[A] and FromConfObj[A] are type classes which describes how to decode config values to type A. Derivation leverages the wonderful shapeless library. All the @Conf macro does is inject an implicit FromConfObj.derive into the case class' companion object.

scala> ConfideFactory.load[AppConfig]()
AppConfig(ApiConf(CacheConf(true,300000000000 nanoseconds),List(Hello, Hola, Bonjour)))
io.estatico

Estatico Studios LLC

Versions

Version
0.0.3
0.0.2
0.0.1