View Source Strukt.Validator.Builder (Strukt v0.4.0)
This module compiles a validator pipeline.
It is largely based on Plug.Builder, with minimal changes.
Link to this section Summary
Functions
Compiles the pipeline.
Link to this section Functions
Compiles the pipeline.
Each pipeline element should be a tuple of {validator_name, options, guards}
This function expects a reversed pipeline, i.e. the last validator to be called comes first in the list.
This function returns a tuple where the first element is a quoted reference to the changeset being validated, and the second element being the compiled quoted pipeline.
example
Example
Strukt.Validator.Builder.compile(env [
{Strukt.Validators.RequireOnInsert, [:field], quote(do: changeset.action == :insert),
{Strukt.Validators.RequireOnUpdate, [:other_field], quote(do: changeset.action == :update)},
{Strukt.Validators.RequireOnChange, [:other_field], true},
], [])