Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to pureconfig 0.9.0 #410

Merged
merged 3 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val catsVersion = "1.0.1"
val jsonpathVersion = "2.4.0"
val macroCompatVersion = "1.1.1"
val macroParadiseVersion = "2.1.1"
val pureconfigVersion = "0.8.0"
val pureconfigVersion = "0.9.0"
val shapelessVersion = "2.3.3"
val scalaCheckVersion = "1.13.5"
val scalaXmlVersion = "1.0.6"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.timepit.refined

import _root_.pureconfig.ConfigConvert
import _root_.pureconfig.error.{CannotConvert, ConfigReaderFailures, ConfigValueLocation}
import _root_.pureconfig.{ConfigConvert, ConfigCursor}
import _root_.pureconfig.error.{CannotConvert, ConfigReaderFailures, ConvertFailure}
import com.typesafe.config.ConfigValue
import eu.timepit.refined.api.{RefType, Validate}
import scala.reflect.runtime.universe.WeakTypeTag
Expand All @@ -14,19 +14,20 @@ package object pureconfig {
validate: Validate[T, P],
typeTag: WeakTypeTag[F[T, P]]
): ConfigConvert[F[T, P]] = new ConfigConvert[F[T, P]] {
override def from(config: ConfigValue): Either[ConfigReaderFailures, F[T, P]] =
configConvert.from(config) match {
override def from(cur: ConfigCursor): Either[ConfigReaderFailures, F[T, P]] =
configConvert.from(cur) match {
case Right(t) =>
refType.refine[P](t) match {
case Left(because) =>
Left(
ConfigReaderFailures(
CannotConvert(
value = config.render(),
toType = typeTag.tpe.toString,
because = because,
location = ConfigValueLocation(config),
path = ""
ConvertFailure(
reason = CannotConvert(
value = cur.value.render(),
toType = typeTag.tpe.toString,
because = because
),
cur = cur
)))

case Right(refined) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import eu.timepit.refined.numeric.Positive
import org.scalacheck.Prop._
import org.scalacheck.Properties
import pureconfig._
import pureconfig.error.{CannotConvert, ConfigReaderFailures}
import pureconfig.error.{CannotConvert, ConfigReaderFailures, ConvertFailure}

class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") {

Expand All @@ -22,10 +22,12 @@ class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") {
property("load failure (predicate)") = secure {
loadConfigWithValue("0") =?
Left(
ConfigReaderFailures(CannotConvert(
value = "0",
toType = "eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[shapeless.nat._0]]",
because = "Predicate failed: (0 > 0).",
ConfigReaderFailures(ConvertFailure(
reason = CannotConvert(
value = "0",
toType = "eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[shapeless.nat._0]]",
because = "Predicate failed: (0 > 0)."
),
location = None,
path = "value"
)))
Expand All @@ -35,10 +37,12 @@ class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") {
loadConfigWithValue("abc") =?
Left(
ConfigReaderFailures(
CannotConvert(
value = "abc",
toType = "Int",
because = "java.lang.NumberFormatException: For input string: \"abc\"",
ConvertFailure(
reason = CannotConvert(
value = "abc",
toType = "Int",
because = "java.lang.NumberFormatException: For input string: \"abc\""
),
location = None,
path = "value"
)))
Expand Down