28 lines
704 B
Elixir
28 lines
704 B
Elixir
defmodule Sukaato.CustomValidators do
|
|
import Ecto.Changeset
|
|
import Validate
|
|
|
|
@moduledoc """
|
|
Provide a collecton of custom validation functions for Ecto database
|
|
database table update validation.
|
|
"""
|
|
|
|
@doc """
|
|
Validate a map , array, or list column for an Ecto database table update.
|
|
|
|
Arity: 3
|
|
|
|
Return Value: changeset || add_err/3
|
|
"""
|
|
def validate_map_format(changeset, field, conventional_mapping) when is_atom(field) do
|
|
field_value = get_field(changeset, field)
|
|
validation_result = validate(field_value, conventional_mapping)
|
|
|
|
if elem(validation_result, 0) == :ok do
|
|
changeset
|
|
else
|
|
add_error(changeset, field, "is not a valid map")
|
|
end
|
|
end
|
|
end
|