Maxine.Ecto (Maxine v1.1.1)

Ecto bindings for Maxine. Provides:

Link to this section Summary

Functions

Changeset helper that uses the current state of the underlying record along with the passed in event to determine what the next state should be, according to the passed in machine. If the change is successful, the new state is written to the field. If not, an error is added to the changeset.

Link to this section Functions

Link to this function

cast_state(changeset, machine, options \\ [])

Specs

cast_state(
  changeset :: %Ecto.Changeset{
    action: term(),
    changes: term(),
    constraints: term(),
    data: term(),
    empty_values: term(),
    errors: term(),
    filters: term(),
    params: term(),
    prepare: term(),
    repo: term(),
    repo_opts: term(),
    required: term(),
    types: term(),
    valid?: term(),
    validations: term()
  },
  machine :: %Maxine.Machine{
    callbacks: term(),
    groups: term(),
    initial: term(),
    transitions: term()
  },
  options :: Maxine.Machine.event_options()
) :: %Ecto.Changeset{
  action: term(),
  changes: term(),
  constraints: term(),
  data: term(),
  empty_values: term(),
  errors: term(),
  filters: term(),
  params: term(),
  prepare: term(),
  repo: term(),
  repo_opts: term(),
  required: term(),
  types: term(),
  valid?: term(),
  validations: term()
}

Changeset helper that uses the current state of the underlying record along with the passed in event to determine what the next state should be, according to the passed in machine. If the change is successful, the new state is written to the field. If not, an error is added to the changeset.

Options

  • :state - the field in which the changeset keeps its state; default is :state
  • :event - the field in which the changeset keeps its current event; default is :event
  • :validate_with - A module implementing validate_state/2 or an equivalent function of arity two for validation

Options will be passed to the underlying call to advance/3 as event options.

Note that it does not look for the relevant state in the params, because we assume cast_state/4 here is the only thing that will ever update that field. Plan accordingly.