-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Akka module for PureConfig | ||
|
||
Adds support for selected [Akka](http://akka.io/) classes to PureConfig. | ||
|
||
## Add pureconfig-akka to your project | ||
|
||
In addition to [core pureconfig](https://github.com/melrief/pureconfig), you'll need: | ||
|
||
```scala | ||
libraryDependencies += "com.github.melrief" %% "pureconfig-akka" % "0.6.0" | ||
``` | ||
|
||
## Example | ||
|
||
To load a `Timeout` into a configuration, we need a class to hold our configuration: | ||
|
||
```scala | ||
import akka.util.Timeout | ||
import com.typesafe.config.ConfigFactory.parseString | ||
import pureconfig._ | ||
import pureconfig.module.akka._ | ||
|
||
case class MyConfig(timeout: Timeout) | ||
``` | ||
|
||
We can read a `MyConfig` like: | ||
```scala | ||
val conf = parseString("""{ timeout: 5 seconds }""") | ||
// conf: com.typesafe.config.Config = Config(SimpleConfigObject({"timeout":"5 seconds"})) | ||
|
||
loadConfig[MyConfig](conf) | ||
// res1: Either[pureconfig.error.ConfigReaderFailures,MyConfig] = Right(MyConfig(Timeout(5 seconds))) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name := "pureconfig-akka" | ||
|
||
organization := "com.github.melrief" | ||
|
||
homepage := Some(url("https://github.com/melrief/pureconfig")) | ||
|
||
licenses := Seq("Mozilla Public License, version 2.0" -> url("https://www.mozilla.org/MPL/2.0/")) | ||
|
||
resolvers ++= Seq( | ||
Resolver.sonatypeRepo("releases"), | ||
Resolver.sonatypeRepo("snapshots") | ||
) | ||
|
||
libraryDependencies ++= Seq( | ||
"com.typesafe.akka" %% "akka-actor" % "2.4.17", | ||
Dependencies.scalaMacrosParadise, | ||
Dependencies.scalaTest | ||
) | ||
|
||
publishMavenStyle := true | ||
|
||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) | ||
Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else | ||
Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
} | ||
|
||
publishArtifact in Test := false | ||
|
||
pomExtra := ( | ||
<scm> | ||
<url>git@github.com:melrief/pureconfig.git</url> | ||
<connection>scm:git:git@github.com:melrief/pureconfig.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>derekmorr</id> | ||
<name>Derek Morr</name> | ||
<url>https://github.com/derekmorr</url> | ||
</developer> | ||
</developers>) | ||
|
||
osgiSettings | ||
|
||
OsgiKeys.exportPackage := Seq("pureconfig.module.javax.*") | ||
|
||
OsgiKeys.privatePackage := Seq() | ||
|
||
OsgiKeys.importPackage := Seq(s"""scala.*;version="[${scalaBinaryVersion.value}.0,${scalaBinaryVersion.value}.50)"""", "*") |
18 changes: 18 additions & 0 deletions
18
modules/akka/src/main/scala/pureconfig/module/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pureconfig.module | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
import _root_.akka.util.Timeout | ||
import com.typesafe.config.ConfigValue | ||
import pureconfig.ConfigConvert | ||
import pureconfig.error.ConfigReaderFailures | ||
|
||
/** | ||
* ConfigConvert instances for Akka value classes. | ||
*/ | ||
package object akka { | ||
implicit val timeoutCC: ConfigConvert[Timeout] = new ConfigConvert[Timeout] { | ||
def from(c: ConfigValue): Either[ConfigReaderFailures, Timeout] = ConfigConvert[FiniteDuration].from(c).right.map(new Timeout(_)) | ||
def to(t: Timeout): ConfigValue = ConfigConvert[FiniteDuration].to(t.duration) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Akka module for PureConfig | ||
|
||
Adds support for selected [Akka](http://akka.io/) classes to PureConfig. | ||
|
||
## Add pureconfig-akka to your project | ||
|
||
In addition to [core pureconfig](https://github.com/melrief/pureconfig), you'll need: | ||
|
||
```scala | ||
libraryDependencies += "com.github.melrief" %% "pureconfig-akka" % "0.6.0" | ||
``` | ||
|
||
## Example | ||
|
||
To load a `Timeout` into a configuration, we need a class to hold our configuration: | ||
|
||
```tut:silent | ||
import akka.util.Timeout | ||
import com.typesafe.config.ConfigFactory.parseString | ||
import pureconfig._ | ||
import pureconfig.module.akka._ | ||
case class MyConfig(timeout: Timeout) | ||
``` | ||
|
||
We can read a `MyConfig` like: | ||
```tut:book | ||
val conf = parseString("""{ timeout: 5 seconds }""") | ||
loadConfig[MyConfig](conf) | ||
``` | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
modules/akka/src/test/scala/pureconfig/module/akka/AkkaSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pureconfig.module.akka | ||
|
||
import scala.concurrent.duration._ | ||
import akka.util.Timeout | ||
import com.typesafe.config.ConfigFactory | ||
import org.scalatest._ | ||
import pureconfig.syntax._ | ||
|
||
class AkkaSuite extends FlatSpec with Matchers with EitherValues { | ||
|
||
case class AkkaConf(timeout: Timeout) | ||
|
||
it should "be able to read a config with a Timeout" in { | ||
val expected = 5.seconds | ||
val config = ConfigFactory.parseString(s"""{ timeout: $expected }""") | ||
config.to[AkkaConf].right.value shouldEqual AkkaConf(Timeout(expected)) | ||
} | ||
} |