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.
Validates that the entity has not expired
Functions
@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
@spec change_public(Ecto.Changeset.t()) :: Ecto.Changeset.t()
Keeps published_at in accord with is_public
@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)
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.
@spec validate_email(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Validates an email for correctness
@spec validate_email_domain(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
@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")
View Source@spec validate_not_expired(Ecto.Changeset.t(), DateTime.t(), atom(), binary()) :: Ecto.Changeset.t()
Validates that the entity has not expired