Validation result, inspired by Ecto changesets.
Contains the validated (and possibly coerced) data alongside any errors.
valid? is true when there are no :error-severity errors (warnings alone
do not cause valid? to be false).
Summary
Functions
Filters errors by column name or row index.
Returns only errors with severity :error (excludes warnings).
Groups errors by column name with interpolated messages.
Returns only errors with severity :warning.
Types
@type t() :: %Scrutinex.Result{ data: [map()], errors: [Scrutinex.Error.t()], valid?: boolean() }
Functions
@spec errors_for( t(), String.t() | [row: non_neg_integer(), check: atom(), severity: :error | :warning] ) :: [Scrutinex.Error.t()]
Filters errors by column name or row index.
Examples
Scrutinex.Result.errors_for(result, "age")
#=> [%Scrutinex.Error{column: "age", ...}]
Scrutinex.Result.errors_for(result, row: 0)
#=> [%Scrutinex.Error{row: 0, ...}]
Scrutinex.Result.errors_for(result, check: :number)
#=> [%Scrutinex.Error{check: :number, ...}]
@spec errors_only(t()) :: [Scrutinex.Error.t()]
Returns only errors with severity :error (excludes warnings).
Examples
Scrutinex.Result.errors_only(result)
#=> [%Scrutinex.Error{severity: :error, ...}]
Groups errors by column name with interpolated messages.
Returns a map of column names to lists of formatted error messages.
Cross-column errors (with column: nil) are grouped under nil.
Examples
Scrutinex.Result.errors_to_map(result)
#=> %{"age" => ["must be greater than 0"], "name" => ["is required"]}
@spec warnings(t()) :: [Scrutinex.Error.t()]
Returns only errors with severity :warning.
Examples
Scrutinex.Result.warnings(result)
#=> [%Scrutinex.Error{severity: :warning, ...}]