Package

com.wix

accord

Permalink

package accord

The entry-point to the Accord library.

Overview

An Accord validator is a typeclass, which adds data validation rules over an existing domain model. The api module deals with the usage site; details on how to define validators can be found in the core module.

To use a validator, simply import this package, make sure the validator is in scope and use the validate function:

scala> import com.wix.accord._
import com.wix.accord._

scala> import MyDomain._
import MyDomain._

scala> val person = Person( name = "Niklaus", surname = "Wirth", age = 81 )
person: MyDomain.Person = Person(Niklaus,Wirth,81)

scala> validate( person )
res0: com.wix.accord.Result = Success

See Result, Success and Failure for details of the result model.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. accord
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class BaseValidator[T] extends Validator[T]

    Permalink

    Simplifies base validator implementation.

    Simplifies base validator implementation. Validators typically consist of an assertion/test and a resulting violation; this implementation takes two functions that describe this behavior and wires the appropriate logic. For example:

    class IsNull extends BaseValidator[ AnyRef ]( _ == null, _ -> "is not a null" )

    T

    The object type this validator operates on.

  2. case class Failure(violations: Set[Violation]) extends Result with Product with Serializable

    Permalink

    An object representing a failed validation result.

    An object representing a failed validation result.

    violations

    The violations that caused the validation to fail.

  3. case class GroupViolation(value: Any, constraint: String, children: Set[Violation], path: Path = Path.empty) extends Violation with Product with Serializable

    Permalink

    Describes the violation of a group of constraints.

    Describes the violation of a group of constraints. For example, the Or combinator found in the built-in combinator library produces a group violation when all of its predicates fail.

    value

    The value of the object which failed validation.

    constraint

    A textual description of the constraint being violated (for example, "doesn't meet any of the requirements").

    children

    The set of violations contained within the group.

    path

    The path to the object under validation.

  4. class MaybeNullSafeValidator[T] extends Validator[T]

    Permalink

    A base validator implementation that, depends on the specified type's nullability, checks for null values prior to executing the specified test.

    A base validator implementation that, depends on the specified type's nullability, checks for null values prior to executing the specified test.

    T

    The object type this validator operates on.

  5. class NullSafeValidator[T <: AnyRef] extends BaseValidator[T]

    Permalink

    An extension to com.wix.accord.BaseValidator that transparently fails on nulls.

    An extension to com.wix.accord.BaseValidator that transparently fails on nulls.

    T

    The object type this validator operates on.

  6. trait Nullability[T] extends AnyRef

    Permalink

    A type class that indicates whether or not a type is nullable.

    A type class that indicates whether or not a type is nullable.

    T

    The type for which nullability is indicated.

  7. sealed trait Result extends AnyRef

    Permalink

    A base trait for validation results.

    A base trait for validation results.

    See also

    com.wix.accord.Success, com.wix.accord.Failure

  8. case class RuleViolation(value: Any, constraint: String, path: Path = Path.empty) extends Violation with Product with Serializable

    Permalink

    Describes a simple validation rule violation (i.e.

    Describes a simple validation rule violation (i.e. one without hierarchy). Most built-in combinators emit this type of violation.

    value

    The value of the object which failed the validation rule.

    constraint

    A textual description of the constraint being violated (for example, "must not be empty").

    path

    The path to the object under validation.

  9. trait Validator[-T] extends (T) ⇒ Result

    Permalink

    A validator over some type T.

    A validator over some type T.

    Overview

    An Accord validator is a function T => Result, where T is the type of the object under validation and Result is an instance of com.wix.accord.Result.

    Implementation note: While theoretically a validator can be defined as a type alias, in practice this doesn't allow to specify an error message when it's implicitly missing at the call site.

    T

    The object type this validator operates on.

    Annotations
    @implicitNotFound( ... )
  10. sealed trait Violation extends AnyRef

    Permalink

    A base trait for all violation types.

  11. trait ViolationBuilder extends AnyRef

    Permalink

    Provides a convenience DSL for generating violations:

    Provides a convenience DSL for generating violations:

    - Rule violations can be created by specifying a value and constraint message as a tuple, for example: v -> "must not be empty" - Group violations can be created by extending the above to include children, as in: v -> "does not match any of the rules" -> Seq( v.firstName -> "first name must be empty", ... )

Value Members

  1. object Descriptions

    Permalink
  2. object Nullability

    Permalink
  3. object Success extends Result with Product with Serializable

    Permalink

    An object representing a successful validation result.

  4. object Validator

    Permalink

    A companion object mostly responsible for allowing null-safe validation of boxed Java primitive types.

  5. object ViolationBuilder extends ViolationBuilder

    Permalink
  6. def validate[T](x: T)(implicit validator: Validator[T]): Result

    Permalink

    Validates the specified object and returns a validation com.wix.accord.Result.

    Validates the specified object and returns a validation com.wix.accord.Result. An implicit com.wix.accord.Validator must be in scope for this call to succeed.

    T

    The type of the object to validate.

    x

    The object to validate.

    validator

    A validator for objects of type T.

    returns

    A com.wix.accord.Result indicating success or failure of the validation.

Deprecated Value Members

  1. object Implicits

    Permalink

    Provides alternative syntax for validation.

    Provides alternative syntax for validation. Instead of having to explicitly call com.wix.accord.validate, an object can be validated by calling instanceUnderTest.validate. This is strictly an aesthetic preference, there are no differences in implementation or execution.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.7) Will be removed in subsequent releases; you can reimplement this easily if needed.

Inherited from AnyRef

Inherited from Any

Ungrouped