Maxine.Ecto (Maxine v0.2.6)

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, event, 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()
  },
  event :: Maxine.Machine.event_name(),
  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

  • :field - the field in which the changeset keeps its state; default is :state

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.