ValidatorDsl

class ValidatorDsl(val state: State, val validators: MutableList<Validator<*>> = mutableListOf(), val condition: () -> Boolean = TRUE)(source)

A domain-specific language (DSL) for creating Validators on a State object.

Parameters

state

the State that this DSL creates Validators for. This State is not modified by the DSL itself

validators

the list into which to store Validators that are created in this DSL

condition

the pre-condition to apply to all Validators created by this DSL. If condition returns false during validation, then the output of the Validators is changed to null. The condition applies only to Validators constructed at this level of nesting of the DSL, and not, for example, to those already in validators at construction time

See also

Constructors

Link copied to clipboard
private constructor(state: State, validators: MutableList<Validator<*>> = mutableListOf(), condition: () -> Boolean = TRUE)

Types

Link copied to clipboard
object Companion

Holds constants.

Link copied to clipboard
inner class OfDsl<T>(val property: KProperty<T>)

A domain-specific language (DSL) for creating Validators for a specific property.

Properties

Link copied to clipboard
private val condition: () -> Boolean
Link copied to clipboard
private val state: State
Link copied to clipboard
private val validators: MutableList<Validator<*>>

Functions

Link copied to clipboard
fun case(condition: () -> Boolean, body: ValidatorDsl.() -> Unit)

Enters a DSL that is like the current one, but makes every Validator constructed inside body return null when condition returns false during validation.

Link copied to clipboard
fun <S : State> include(property: KProperty<S>, condition: () -> Boolean = TRUE)

Includes all Validators of the given property, but skips them during validation when condition is false.

Link copied to clipboard
fun <T> of(property: KProperty<T>): ValidatorDsl.OfDsl<T>

Enters a DSL for constructing Validators for the given property.

Link copied to clipboard
private fun <T> validator(property: KProperty<T>, validate: (T) -> ValidationInfo?): Validator<T>

Wraps around the default Validator constructor, but additionally adds the created Validator to validators.