-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove more ficus from the ride runner
- Loading branch information
1 parent
2f1a82a
commit 0007744
Showing
4 changed files
with
45 additions
and
30 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
38 changes: 38 additions & 0 deletions
38
ride-runner/src/main/scala/com/wavesplatform/ride/runner/input/PureconfigImplicits.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,38 @@ | ||
package com.wavesplatform.ride.runner.input | ||
|
||
import com.typesafe.config.{ConfigFactory, ConfigRenderOptions} | ||
import com.wavesplatform.account.Address | ||
import com.wavesplatform.json.JsonManipulations | ||
import play.api.libs.json.{JsError, JsObject, JsSuccess, JsValue, Json, Reads} | ||
import pureconfig.ConfigReader | ||
import pureconfig.error.CannotConvert | ||
|
||
object PureconfigImplicits { | ||
|
||
implicit val jsObjectConfigReader: ConfigReader[JsObject] = playJsonConfigReader | ||
|
||
implicit val jsValueConfigReader: ConfigReader[JsValue] = playJsonConfigReader | ||
|
||
private def playJsonConfigReader[T: Reads]: ConfigReader[T] = ConfigReader.fromCursor { cur => | ||
for { | ||
configValue <- cur.asConfigValue | ||
stubKey = "stubKey" | ||
config = ConfigFactory.empty().withValue(stubKey, configValue) | ||
} yield { | ||
val jsonStr = config.root().render(ConfigRenderOptions.concise()) | ||
JsonManipulations | ||
.pick(Json.parse(jsonStr), stubKey) | ||
.getOrElse(fail(s"Expected a value")) | ||
.validate[T] match { | ||
case JsSuccess(value, _) => value | ||
case JsError(errors) => fail(s"Can't parse: ${errors.mkString("\n")}") | ||
} | ||
} | ||
} | ||
|
||
|
||
implicit val addressConfigReader: ConfigReader[Address] = | ||
ConfigReader.fromString(s => Address.fromString(s).left.map(_ => CannotConvert(s, "Address", "invalid address"))) | ||
|
||
private def fail(message: String, cause: Throwable = null) = throw new IllegalArgumentException(message, cause) | ||
} |
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