Skip to content

Commit

Permalink
Fix Seq Validation (#219)
Browse files Browse the repository at this point in the history
* Initial fix for repeated validation

* Use more specific FieldValidator type

* flesh out ValidatorTest

* scalafmt & scalastyle

* Scalastyle deactivate overrides

Co-authored-by: Jack Dingilian <[email protected]>
  • Loading branch information
jackdingilian and Jack Dingilian authored Mar 1, 2022
1 parent dadb722 commit 462268a
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ object CaseClassValidators {
val fiveNFiveVal: Validator[FiveNestedFiveFields] = genFiveNestedFive()
}

//scalastyle:off magic.number
object Fields {
import CaseClassesToValidate._

Expand Down Expand Up @@ -252,3 +253,4 @@ class Benchmarking {
fiveNFiveVal.validateRecord(Unvalidated(fiveN5))
}
}
//scalastyle:on magic.number
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.spotify.elitzur.validators

import com.spotify.elitzur.MetricsReporter

import scala.reflect.ClassTag

trait Implicits {
Expand All @@ -37,10 +39,10 @@ trait Implicits {
implicit def wrappedValidator[T: Validator]: Validator[ValidationStatus[T]] = new WrappedValidator[T]
implicit def optionValidator[T: Validator]: Validator[Option[T]] = new OptionValidator[T]
implicit def dynamicTypeValidator[T <: DynamicValidationType[_, _, _]: ClassTag]: DynamicValidator[T] = new DynamicValidator[T]
implicit def seqValidator[T: Validator: ClassTag]: Validator[Seq[T]] = wrapSeqLikeValidator(() => Seq.newBuilder[T])
implicit def listValidator[T: Validator: ClassTag]: Validator[List[T]] = wrapSeqLikeValidator(() => List.newBuilder[T])
implicit def arrayValidator[T: Validator: ClassTag]: Validator[Array[T]] = wrapSeqLikeValidator(() => Array.newBuilder[T])
implicit def vectorValidator[T: Validator: ClassTag]: Validator[Vector[T]] = wrapSeqLikeValidator(() => Vector.newBuilder[T])
implicit def seqValidator[T: Validator: ClassTag](implicit reporter: MetricsReporter): Validator[Seq[T]] = wrapSeqLikeValidator(() => Seq.newBuilder[T])
implicit def listValidator[T: Validator: ClassTag](implicit reporter: MetricsReporter): Validator[List[T]] = wrapSeqLikeValidator(() => List.newBuilder[T])
implicit def arrayValidator[T: Validator: ClassTag](implicit reporter: MetricsReporter): Validator[Array[T]] = wrapSeqLikeValidator(() => Array.newBuilder[T])
implicit def vectorValidator[T: Validator: ClassTag](implicit reporter: MetricsReporter): Validator[Vector[T]] = wrapSeqLikeValidator(() => Vector.newBuilder[T])
//scalastyle:on line.size.limit

}
Loading

0 comments on commit 462268a

Please sign in to comment.