BitcrowdEcto.Changeset (bitcrowd_ecto v0.2.0) View Source

Extensions for Ecto changesets.

Link to this section Summary

Functions

Validates that a field that has been changed.

Validates that an email has valid format.

Validates that a field is not changed from its current value, unless the current value is nil.

Validates that a field has changed in a defined way.

Validates a field url to be qualified url

Link to this section Functions

Link to this function

validate_changed(changeset, field)

View Source (since 0.1.0)

Specs

validate_changed(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates that a field that has been changed.

Link to this function

validate_email(changeset, field, opts \\ [])

View Source (since 0.1.0)

Specs

validate_email(Ecto.Changeset.t(), atom(), [{:max_length, non_neg_integer()}]) ::
  Ecto.Changeset.t()

Validates that an email has valid format.

  • Ignores nil values.

Compliance

For a good list of valid/invalid emails, see https://gist.github.com/cjaoude/fd9910626629b53c4d25

The regex used in this validator doesn't understand half of the inputs, but we don't really care for now. Validating super strange emails is not a sport we want to compete in.

Link to this function

validate_immutable(changeset, field)

View Source (since 0.1.0)

Specs

validate_immutable(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates that a field is not changed from its current value, unless the current value is nil.

Link to this function

validate_transition(changeset, field, transitions)

View Source (since 0.1.0)

Specs

validate_transition(Ecto.Changeset.t(), atom(), [{any(), any()}]) ::
  Ecto.Changeset.t()

Validates that a field has changed in a defined way.

Examples

validate_transition(changeset, field, [{"foo", "bar"}, {"foo", "yolo"}]

This marks the changeset invalid unless the value of :field is currently "foo" and is changed to "bar" or "yolo". If the field is not changed, a {state, state} transition has to be present in the list of transitions.

Link to this function

validate_url(changeset, field)

View Source (since 0.1.0)

Specs

validate_url(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates a field url to be qualified url