Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into enable-coverage-for-scala-3
- Loading branch information
Showing
32 changed files
with
219 additions
and
44 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
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
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
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
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
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
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
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
49 changes: 44 additions & 5 deletions
49
modules/http4s/src/main/scala/pureconfig/module/http4s/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 |
---|---|---|
@@ -1,16 +1,55 @@ | ||
package pureconfig.module | ||
|
||
import org.http4s.Uri | ||
import scala.reflect.ClassTag | ||
|
||
import org.http4s.{ParseResult, Uri} | ||
|
||
import pureconfig.error.CannotConvert | ||
import pureconfig.{ConfigReader, ConfigWriter} | ||
|
||
package object http4s { | ||
private def mkConfigReader[A](f: String => ParseResult[A])(implicit ct: ClassTag[A]): ConfigReader[A] = | ||
ConfigReader.fromString { str => | ||
val className = ct.runtimeClass.getSimpleName() | ||
f(str).fold( | ||
err => Left(CannotConvert(str, className, err.sanitized)), | ||
value => Right(value) | ||
) | ||
} | ||
|
||
implicit val uriReader: ConfigReader[Uri] = | ||
ConfigReader.fromString(str => | ||
Uri.fromString(str).fold(err => Left(CannotConvert(str, "Uri", err.sanitized)), uri => Right(uri)) | ||
) | ||
mkConfigReader[Uri](Uri.fromString) | ||
|
||
implicit val uriWriter: ConfigWriter[Uri] = | ||
ConfigWriter[String].contramap(_.renderString) | ||
|
||
implicit val uriSchemeReader: ConfigReader[Uri.Scheme] = | ||
mkConfigReader[Uri.Scheme](Uri.Scheme.fromString) | ||
|
||
implicit val uriSchemeWriter: ConfigWriter[Uri.Scheme] = | ||
ConfigWriter[String].contramap(_.value) | ||
|
||
implicit val uriPathReader: ConfigReader[Uri.Path] = | ||
ConfigReader.stringConfigReader.map(Uri.Path.unsafeFromString) // .fromString is deprecated | ||
|
||
implicit val uriPathWriter: ConfigWriter[Uri.Path] = | ||
ConfigWriter[String].contramap(_.renderString) | ||
|
||
implicit val uriHostReader: ConfigReader[Uri.Host] = | ||
mkConfigReader[Uri.Host](Uri.Host.fromString) | ||
|
||
implicit val uriHostWriter: ConfigWriter[Uri.Host] = | ||
ConfigWriter[String].contramap(_.renderString) | ||
|
||
implicit val uriIpv4AddressReader: ConfigReader[Uri.Ipv4Address] = | ||
mkConfigReader[Uri.Ipv4Address](Uri.Ipv4Address.fromString) | ||
|
||
implicit val uriIpv4AddressWriter: ConfigWriter[Uri.Ipv4Address] = | ||
ConfigWriter[String].contramap(_.renderString) | ||
|
||
implicit val uriIpv6AddressReader: ConfigReader[Uri.Ipv6Address] = | ||
mkConfigReader[Uri.Ipv6Address](Uri.Ipv6Address.fromString) | ||
|
||
implicit val uriWriter: ConfigWriter[Uri] = ConfigWriter[String].contramap(_.renderString) | ||
implicit val uriIpv6AddressWriter: ConfigWriter[Uri.Ipv6Address] = | ||
ConfigWriter[String].contramap(_.value) // Uses .value so that we can round-trip as Ipv6Address | ||
} |
Oops, something went wrong.