Skip to content

Commit

Permalink
Rm zio
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnu-liguobin committed Nov 13, 2023
1 parent 43c72e5 commit 6855d5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 98 deletions.
15 changes: 7 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,23 @@ lazy val root = project
name := "validation-scala",
publish / skip := true
)
.aggregate(zio, core)
.aggregate(ext, core)

lazy val zio = project
.in(file("zio"))
lazy val ext = project
.in(file("ext"))
.settings(commonSettings)
.settings(
name := "validation-scala-zio",
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion % Provided
)
name := "validation-scala-ext",
scalaVersion := scala3_Version
)
.dependsOn(core)

lazy val core = project
.in(file("core"))
.settings(commonSettings)
.settings(
name := "validation-scala",
name := "validation-scala",
scalaVersion := scala3_Version,
Compile / doc / scalacOptions ++= {
// Work around 2.12 bug which prevents javadoc in nested java classes from compiling.
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
11 changes: 11 additions & 0 deletions ext/src/main/scala/bitlap/validation/ext/FieldChecker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bitlap
package validation
package ext

trait FieldChecker {
self =>
@inline def check(): Boolean = Validator.validate(self)

check()

}
24 changes: 24 additions & 0 deletions ext/src/main/scala/bitlap/validation/ext/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package bitlap.validation

package object ext {

lazy val Validator: GenericeScalaValidator[Identity] = ScalaValidatorFactory.scalaValidator()

implicit final class ValidationExt(val genericValidator: GenericeScalaValidator[Identity]) extends AnyVal {

def checkArgument[T](obj: T, groups: Class[_]*): Identity[Boolean] = {
val errors = genericValidator
.validate(obj)
.map(violation => (violation.getPropertyPath.toString, violation.getMessage, violation.getInvalidValue))
.toList
if (errors.nonEmpty) {
throw new IllegalArgumentException(
errors
.map(pathMessageValue => s"""${pathMessageValue._1}=${pathMessageValue._3}, error=${pathMessageValue._2}""")
.mkString(" and ")
)
} else true
}

}
}
54 changes: 0 additions & 54 deletions zio/src/main/scala/bitlap/validation/ZioValidatorFactory.scala

This file was deleted.

36 changes: 0 additions & 36 deletions zio/src/main/scala/bitlap/validation/package.scala

This file was deleted.

0 comments on commit 6855d5a

Please sign in to comment.