com.wix.accord

dsl

package dsl

Provides a DSL for defining validation rules. For example:

import dsl._ // Import the validator DSL

case class Person( firstName: String, lastName: String ) case class Classroom( teacher: Person, students: Seq[ Person ] )

implicit val personValidator = validator[ Person ] { p => p.firstName is notEmpty p.lastName is notEmpty }

implicit val classValidator = validator[ Classroom ] { c => c.teacher is valid // Implicitly relies on personValidator! c.students.each is valid c.students have size > 0 }

These validators can later be executed via com.wix.accord.validate. A macro transforms each validation block into a chain of validation rules at compile-time, and annotates accesses to getters so that violation messages are automatically generated; for instance, the rule p.firstName is notEmpty will generate the violation message "firstName must not be empty" automatically.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. dsl
  2. BooleanOps
  3. OrderingOps
  4. GenericOps
  5. CollectionOps
  6. StringOps
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. trait BooleanOps extends AnyRef

    Provides a DSL for booleans.

  2. class CollectionDslContext[Inner, Outer] extends SizeContext[Inner, Outer] with ContextTransformer[Inner, Outer]

  3. trait CollectionOps extends AnyRef

    Provides a DSL for collection-like objects.

    Provides a DSL for collection-like objects. Works in conjunction with com.wix.accord.dsl.DslContext.

  4. trait ContextTransformer[Inner, Outer] extends AnyRef

  5. implicit class Contextualizer[U] extends SimpleDslContext[U]

    Wraps expressions under validation with a specialized scope (this is later used during the macro transform).

    Wraps expressions under validation with a specialized scope (this is later used during the macro transform). Enables syntax such as p.firstName is notEmpty, where p.firstName is the actual expression under validation.

    U

    The type of the provided expression.

  6. implicit class Descriptor[U] extends AnyRef

    Wraps expression under validation with an explicit description; after macro transformation, the resulting validator will use the specified description to render violations.

    Wraps expression under validation with an explicit description; after macro transformation, the resulting validator will use the specified description to render violations. See the com.wix.accord.dsl.Descriptor.as method for an example.

    U

    The type of the provided expression.

  7. trait DslContext[Inner, Outer] extends AnyRef

  8. trait GenericOps extends AnyRef

    Provides a DSL for untyped validators.

  9. type HasSize = Any { def size: Int }

    A structural type representing any object that has a size.

    A structural type representing any object that has a size.

    Definition Classes
    CollectionOps
  10. trait OrderingOps extends AnyRef

    Provides a DSL for objects implementing scala.math.Ordering.

    Provides a DSL for objects implementing scala.math.Ordering.

    Implementation note: All methods here should only require scala.math.PartialOrdering, but the canonical implicits are defined in the Ordering companion and would therefore not be imported by default at the call site.

  11. trait SimpleDslContext[U] extends DslContext[U, U] with ContextTransformer[U, U]

  12. trait SizeContext[Inner, Outer] extends AnyRef

  13. trait StringOps extends AnyRef

    Provides a DSL for string validators.

  14. implicit class ValidatorBooleanOps[T] extends AnyRef

    Extends validators with useful helpers.

    Extends validators with useful helpers.

    Definition Classes
    BooleanOps

Value Members

  1. def <[T](other: T)(implicit arg0: Ordering[T]): combinators.LesserThan[T]

    Generates a validator that succeeds only if the provided value is less than the specified bound.

    Generates a validator that succeeds only if the provided value is less than the specified bound.

    Definition Classes
    OrderingOps
  2. def <=[T](other: T)(implicit arg0: Ordering[T]): combinators.LesserThanOrEqual[T]

    Generates a validator that succeeds if the provided value is less than or equal to the specified bound.

    Generates a validator that succeeds if the provided value is less than or equal to the specified bound.

    Definition Classes
    OrderingOps
  3. def ==[T](other: T)(implicit arg0: Ordering[T]): combinators.EquivalentTo[T]

    Generates a validator that succeeds if the provided value is exactly equal to the specified value.

    Generates a validator that succeeds if the provided value is exactly equal to the specified value.

    Definition Classes
    OrderingOps
  4. def >[T](other: T)(implicit arg0: Ordering[T]): combinators.GreaterThan[T]

    Generates a validator that succeeds only if the provided value is greater than the specified bound.

    Generates a validator that succeeds only if the provided value is greater than the specified bound.

    Definition Classes
    OrderingOps
  5. def >=[T](other: T)(implicit arg0: Ordering[T]): combinators.GreaterThanOrEqual[T]

    Generates a validator that succeeds if the provided value is greater than or equal to the specified bound.

    Generates a validator that succeeds if the provided value is greater than or equal to the specified bound.

    Definition Classes
    OrderingOps
  6. def aNull: Validator[AnyRef]

    Specifies a validator that succeeds only if the validation expression is null.

    Specifies a validator that succeeds only if the validation expression is null.

    Definition Classes
    GenericOps
  7. val be: OrderingOps

    A proxy for ordering ops.

    A proxy for ordering ops. Enables syntax such as p.age should be > 5.

  8. def between[T](lowerBound: T, upperBound: T)(implicit arg0: Ordering[T]): combinators.InRangeInclusive[T]

    Generates a validator that succeeds if the provided value is between (inclusive) the specified bounds.

    Generates a validator that succeeds if the provided value is between (inclusive) the specified bounds. The method exclusive is provided to specify an exclusive upper bound.

    Definition Classes
    OrderingOps
  9. implicit def booleanToBooleanValidator(b: Boolean): Validator[Boolean]

    An implicit conversion from boolean to a respective IsTrue/IsFalse instance; this enables syntax such as customer.emailOptIn is true.

    An implicit conversion from boolean to a respective IsTrue/IsFalse instance; this enables syntax such as customer.emailOptIn is true.

    Definition Classes
    BooleanOps
  10. def empty[T <: AnyRef](implicit arg0: (T) ⇒ combinators.HasEmpty): Validator[T]

    Specifies a validator that succeeds on empty instances; the object under validation must implement def isEmpty: Boolean (see com.wix.accord.combinators.HasEmpty).

    Specifies a validator that succeeds on empty instances; the object under validation must implement def isEmpty: Boolean (see com.wix.accord.combinators.HasEmpty).

    Definition Classes
    CollectionOps
  11. def endWith(suffix: String): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression ends with the specified suffix.

    Specifies a validator that operates on strings and succeeds only if the validation expression ends with the specified suffix.

    Definition Classes
    StringOps
  12. def equalTo[T](to: T): Validator[T]

    Specifies a validator that succeeds only if the validation expression is equal to the specified value.

    Specifies a validator that succeeds only if the validation expression is equal to the specified value. Respects nulls an performs equality checks via java.lang.Object.equals.

    Definition Classes
    GenericOps
  13. implicit def genericTraversableOnce2HasSize[T](gto: T)(implicit ev: (T) ⇒ GenTraversableOnce[_]): HasSize

    An implicit conversion to enable any collection-like object (e.

    An implicit conversion to enable any collection-like object (e.g. strings, options) to be handled by com.wix.accord.dsl.SizeContext.

    java.lang.String does not directly implement size (in practice it is implemented in scala.collection.IndexedSeqOptimized via an implicit conversion and an inheritance stack), and this is a case where the Scala compiler does not always infer structural types correctly. By requiring a view bound from T to scala.collection.GenTraversableOnce we can force any collection-like structure to conform to the structural type com.wix.accord.dsl.CollectionOps.HasSize, and by requiring a view bound from T to com.wix.accord.dsl.CollectionOps.HasSize at the call site (via com.wix.accord.dsl.SizeContext) we additionally support any class that directly conforms to the structural type as well.

    T

    The type that conforms, directly or implicitly, to com.wix.accord.dsl.CollectionOps.HasSize.

    gto

    An object that is, or is implicitly convertible to, scala.collection.GenTraversableOnce.

    returns

    The specified object, strictly-typed as com.wix.accord.dsl.CollectionOps.HasSize.

    Definition Classes
    CollectionOps
  14. def matchRegex(pattern: Pattern): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Definition Classes
    StringOps
  15. def matchRegex(regex: Regex): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Definition Classes
    StringOps
  16. def matchRegex(regex: String): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression matches the specified regular expression.

    Definition Classes
    StringOps
  17. def matchRegexFully(pattern: Pattern): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.

    Definition Classes
    StringOps
  18. def matchRegexFully(regex: Regex): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.

    Definition Classes
    StringOps
  19. def matchRegexFully(regex: String): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression.

    Specifies a validator that operates on strings and succeeds only if the validation expression **fully** matches the specified regular expression. See com.wix.accord.combinators.StringCombinators.MatchesRegex for a full explanation of the difference between partial and full matching.

    Definition Classes
    StringOps
  20. def notEmpty[T <: AnyRef](implicit arg0: (T) ⇒ combinators.HasEmpty): Validator[T]

    Specifies a validator that fails on empty instances; the object under validation must implement def isEmpty: Boolean (see com.wix.accord.combinators.HasEmpty).

    Specifies a validator that fails on empty instances; the object under validation must implement def isEmpty: Boolean (see com.wix.accord.combinators.HasEmpty).

    Definition Classes
    CollectionOps
  21. def notEqualTo[T](to: T): Validator[T]

    Specifies a validator that succeeds only if the validation expression is not equal to the specified value.

    Specifies a validator that succeeds only if the validation expression is not equal to the specified value. Respects nulls an performs equality checks via java.lang.Object.equals.

    Definition Classes
    GenericOps
  22. def notNull: Validator[AnyRef]

    Specifies a validator that succeeds only if the validation expression is not null.

    Specifies a validator that succeeds only if the validation expression is not null.

    Definition Classes
    GenericOps
  23. val size: OrderingOps

    Provides access to size-based validators (where the object under validation must implement def size: Int, see com.wix.accord.dsl.CollectionOps.HasSize).

    Provides access to size-based validators (where the object under validation must implement def size: Int, see com.wix.accord.dsl.CollectionOps.HasSize). Enables syntax such as c.students has size > 0.

    Definition Classes
    CollectionOps
  24. def snippet: String

    Attributes
    protected
    Definition Classes
    OrderingOps
  25. def startWith(prefix: String): Validator[String]

    Specifies a validator that operates on strings and succeeds only if the validation expression starts with the specified prefix.

    Specifies a validator that operates on strings and succeeds only if the validation expression starts with the specified prefix.

    Definition Classes
    StringOps
  26. def valid[T](implicit validator: Validator[T]): Validator[T]

    Delegates validation to a pre-defined validation rule, which is encoded as an implicit com.wix.accord.Validator in scope.

    Delegates validation to a pre-defined validation rule, which is encoded as an implicit com.wix.accord.Validator in scope. Enables composition of validation rules, as in:

    case class Address( address1: String, address2: String, city: String, ... ) case class Item( sku: String, count: Int, ... ) case class Shipment( items: Seq[ Item ], address: Location, ... )

    implicit val addressValidator = validator[ Address ] { ... } implicit val itemValidator = validator[ Item ] { ... }

    implicit val shipmentValidator = validator[ Shipment ] { shipment => shipment.address is valid // Implicitly uses addressValidator shipment.items.each is valid // Implicitly uses itemValidator }

    Definition Classes
    GenericOps
  27. macro def validator[T](v: (T) ⇒ Unit): TransformedValidator[T]

    Takes a code block and rewrites it into a validation chain (see description in com.wix.accord.dsl.

    Takes a code block and rewrites it into a validation chain (see description in com.wix.accord.dsl.

    T

    The type under validation.

    v

    The validation code block; may contain any combination of validation statements.

    returns

    The validation code block rewritten as a com.wix.accord.Validator for the specified type T.

  28. def within[T](range: NumericRange[T])(implicit arg0: Ordering[T]): combinators.InRange[T]

    Generates a validator that succeeds if the provided value is within the specified range.

    Generates a validator that succeeds if the provided value is within the specified range.

    Definition Classes
    OrderingOps
  29. def within(range: Range): combinators.InRange[Int]

    Generates a validator that succeeds if the provided value is within the specified range.

    Generates a validator that succeeds if the provided value is within the specified range.

    Definition Classes
    OrderingOps

Inherited from BooleanOps

Inherited from OrderingOps

Inherited from GenericOps

Inherited from CollectionOps

Inherited from StringOps

Inherited from AnyRef

Inherited from Any

Ungrouped