View Source Bonfire.Common.Repo.Utils (Bonfire v0.9.11-social-beta.3)

Helper functions for changesets

Summary

Functions

Keeps disabled_at in accord with is_disabled

Keeps muted_at in accord with is_muted

Keeps published_at in accord with is_public

If a changeset includes a change to bool_field, we ensure that the timestamp field is updated if required. In the case of true, this means setting it to now if it is null and in the case of false, this means setting it to null if it is not null.

If a changeset includes a change to bool_field, we change two timestamps columns (representing activated and deactivated) so that only one is set to a non-null value at a time.

Validates an email for correctness

Validates that a URL uses HTTP(S) and has a correct format.

Functions

change_disabled(changeset)

@spec change_disabled(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Keeps disabled_at in accord with is_disabled

change_muted(changeset)

@spec change_muted(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Keeps muted_at in accord with is_muted

change_public(changeset)

@spec change_public(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Keeps published_at in accord with is_public

change_synced_timestamp(changeset, bool_field, timestamp_field)

@spec change_synced_timestamp(Ecto.Changeset.t(), atom(), atom()) ::
  Ecto.Changeset.t()

If a changeset includes a change to bool_field, we ensure that the timestamp field is updated if required. In the case of true, this means setting it to now if it is null and in the case of false, this means setting it to null if it is not null.

change_synced_timestamps(changeset, bool_field, on_field, off_field, default \\ true)

@spec change_synced_timestamps(Ecto.Changeset.t(), atom(), atom(), atom(), atom()) ::
  Ecto.Changeset.t()

If a changeset includes a change to bool_field, we change two timestamps columns (representing activated and deactivated) so that only one is set to a non-null value at a time.

match_admin()

(macro)

validate_email(changeset, field)

@spec validate_email(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates an email for correctness

validate_email_domain(changeset, field)

@spec validate_email_domain(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

validate_exactly_one(changeset, columns, message)

validate_http_url(changeset, field)

@spec validate_http_url(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates that a URL uses HTTP(S) and has a correct format.

validate_not_expired(cs, now \\ DateTime.utc_now(), column \\ :expires_at, message \\ "expired")

@spec validate_not_expired(Ecto.Changeset.t(), DateTime.t(), atom(), binary()) ::
  Ecto.Changeset.t()

Validates that the entity has not expired