Kronky v0.5.0 Kronky.ChangesetParser View Source

Converts an ecto changeset into a list of validation errors structs. Currently does not support nested errors

Link to this section Summary

Functions

Generate a single Kronky.ValidationMessage struct from a changeset

Generate a list of Kronky.ValidationMessage structs from changeset errors

Inserts message variables into message

Extract a nested map of raw errors from a changeset

Generate unique code for each validation type

Link to this section Functions

Link to this function construct_message(field, error_tuple) View Source

Generate a single Kronky.ValidationMessage struct from a changeset.

This method is designed to be used with Ecto.Changeset.traverse_errors to generate a map of structs.

## Examples

```
error_map = Changeset.traverse_errors(fn(changeset, field, error) ->
  Kronky.ChangesetParser.construct_message(field, error)
end)
error_list = Enum.flat_map(error_map, fn({_, messages}) -> messages end)

```
Link to this function extract_messages(changeset) View Source

Generate a list of Kronky.ValidationMessage structs from changeset errors

For examples, please see the test cases in the github repo.

Link to this function interpolate_message(arg) View Source

Inserts message variables into message.

Examples

iex> interpolate_message({"length should be between %{one} and %{two}", [one: "1", two: "2", three: "3"]})
"length should be between 1 and 2"
Link to this function messages_as_map(changeset) View Source

Extract a nested map of raw errors from a changeset

For examples, please see the test cases in the github repo.

Generate unique code for each validation type.

Expects an array of validation options such as those supplied by Ecto.Changeset.traverse_errors/2, with the addition of a message key containing the message string. Messages are required for several validation types to be identified.

Supported