Strukt.Validator behaviour (Strukt v0.3.1) View Source

This module defines the behaviour for validator modules which can be used in validation pipelines over Strukt-defined structs.

Link to this section Summary

Callbacks

This is called during validation to generate the options provided to validate/2. The input is whatever was given as the second argument to Strukt.validation/2, and any term is allowed to be returned. The return value will be passed as-is to the validate/2 callback.

Called during validation.

Link to this section Types

Specs

opts() :: any()

Link to this section Callbacks

Specs

init(opts()) :: opts()

This is called during validation to generate the options provided to validate/2. The input is whatever was given as the second argument to Strukt.validation/2, and any term is allowed to be returned. The return value will be passed as-is to the validate/2 callback.

Specs

validate(Ecto.Changeset.t(), opts()) :: Ecto.Changeset.t()

Called during validation.

The implementation is allowed to mutate the changeset as desired, but must return a new changeset regardless of whether the changeset it received was valid or not, but with relevant errors added.