AntlUtilsEcto.Changeset (antl_utils_ecto v2.13.2)

View Source

Set of utils for Ecto.Changeset

Summary

Functions

A helper that transforms changeset errors into a map of messages.

A helper that convert changeset error to string (as json encoded format).

A helper that allows to apply function on a changeset only if it is valid. Always returns the changeset

Validates the given fields change are empty or unchanged.

Functions

errors_on(changeset)

@spec errors_on(Ecto.Changeset.t()) :: %{optional(atom()) => [binary()]}

A helper that transforms changeset errors into a map of messages.

Examples

iex> changeset = Ecto.Changeset.change({%{}, %{password: :string}}) |> Ecto.Changeset.cast(%{password: 123}, [:password]) iex> assert "is invalid" in AntlUtilsEcto.Changeset.errors_on(changeset).password iex> assert %{password: ["is invalid"]} = AntlUtilsEcto.Changeset.errors_on(changeset)

json_encode_errors(changeset)

@spec json_encode_errors(Ecto.Changeset.t()) :: String.t()

A helper that convert changeset error to string (as json encoded format).

on_valid_changeset(changeset, fun)

@spec on_valid_changeset(Ecto.Changeset.t(), (Ecto.Changeset.t() ->
                                          Ecto.Changeset.t())) ::
  Ecto.Changeset.t()

A helper that allows to apply function on a changeset only if it is valid. Always returns the changeset

validate_datetime_gt(changeset, datetime_key, referal, opts \\ [])

@spec validate_datetime_gt(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()

validate_datetime_gte(changeset, datetime_key, referal, opts \\ [])

@spec validate_datetime_gte(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()

validate_datetime_inclusion(changeset, start_at_key, end_at_key, container_period)

@spec validate_datetime_inclusion(
  Ecto.Changeset.t(),
  atom(),
  atom(),
  AntlUtilsElixir.DateTime.Period.t()
) :: Ecto.Changeset.t()

validate_datetime_inclusion(changeset, start_at_key, end_at_key, period, period_start_at_key, period_end_at_key)

@spec validate_datetime_inclusion(
  Ecto.Changeset.t(),
  atom(),
  atom(),
  map(),
  atom(),
  atom()
) ::
  Ecto.Changeset.t()

validate_datetime_lt(changeset, datetime_key, referal, opts \\ [])

@spec validate_datetime_lt(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()

validate_datetime_lte(changeset, datetime_key, referal, opts \\ [])

@spec validate_datetime_lte(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()

validate_empty(changeset, fields, opts \\ [])

@spec validate_empty(Ecto.Changeset.t(), any(), keyword()) :: Ecto.Changeset.t()

Validates the given fields change are empty or unchanged.

validate_empty_if(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_empty_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()

validate_empty_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_empty_unless(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()

validate_empty_with(changeset, fields, conditional_fields, opts \\ [])

@spec validate_empty_with(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_empty_with_all(changeset, fields, conditional_fields, opts \\ [])

@spec validate_empty_with_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_empty_without(changeset, fields, conditional_fields, opts \\ [])

@spec validate_empty_without(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_empty_without_all(changeset, fields, conditional_fields, opts \\ [])

@spec validate_empty_without_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_required_any(changeset, fields, opts \\ [])

@spec validate_required_any(Ecto.Changeset.t(), list(), keyword()) ::
  Ecto.Changeset.t()

validate_required_any_if(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_required_any_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()

validate_required_any_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_required_any_unless(
  Ecto.Changeset.t(),
  any(),
  atom(),
  any(),
  keyword()
) ::
  Ecto.Changeset.t()

validate_required_if(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_required_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()

validate_required_if_any(changeset, fields, conditional_field, expected_values, opts \\ [])

@spec validate_required_if_any(Ecto.Changeset.t(), any(), atom(), list(), keyword()) ::
  Ecto.Changeset.t()

validate_required_one_exclusive(changeset, fields, opts \\ [])

@spec validate_required_one_exclusive(Ecto.Changeset.t(), [any()], keyword()) ::
  Ecto.Changeset.t()

validate_required_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

@spec validate_required_unless(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()

validate_required_with(changeset, fields, conditional_fields, opts \\ [])

@spec validate_required_with(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_required_with_all(changeset, fields, conditional_fields, opts \\ [])

@spec validate_required_with_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()

validate_required_without(changeset, fields, conditional_fields, opts \\ [])

@spec validate_required_without(
  Ecto.Changeset.t(),
  any(),
  atom() | [atom()],
  keyword()
) ::
  Ecto.Changeset.t()

validate_required_without_all(changeset, fields, conditional_fields, opts \\ [])

@spec validate_required_without_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()