View Source Bonfire.Common.Repo.Utils (Bonfire v0.9.10-classic-beta.169)

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

Link to this function

change_disabled(changeset)

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

Keeps disabled_at in accord with is_disabled

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

Keeps muted_at in accord with is_muted

Link to this function

change_public(changeset)

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

Keeps published_at in accord with is_public

Link to this function

change_synced_timestamp(changeset, bool_field, timestamp_field)

View Source
@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.

Link to this function

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

View Source
@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.

Link to this function

validate_email(changeset, field)

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

Validates an email for correctness

Link to this function

validate_email_domain(changeset, field)

View Source
@spec validate_email_domain(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Link to this function

validate_exactly_one(changeset, columns, message)

View Source
Link to this function

validate_http_url(changeset, field)

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

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

Link to this function

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

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

Validates that the entity has not expired