API Reference state_machine v0.1.6

Modules

StateMachine package implements state machine abstraction. It supports Ecto out of the box and can work as both data structure and a process powered by gen_statem.

Callback defines a captured function, that can be called in a various points of a State Machine's lifecycle. Depending on return type (shape) of the callback, it can update the context or the model, stop the transition with error, or be ignored.

Context is a container for all metadata supporting the transition. Normally users should not have anything to do with Contexts, however some public functions might expose it. For example, user can (but discuraged) manipulate the Context in callbacks.

These macros help generating State Machine definition in a given Module.

This addition makes StateMachine fully compatible with Ecto.

Event is a container for transitions. It is identified by name (atom) and can contain arbitrary number of transtitions.

Guards are functions that help to decide whether it's allowed to proceed with Event or Transition. They might serve different purposes

Introspection functions allow you to collect and analyze meta information about state machine in runtime. For example, you might want to send the full list of states or events to the front-end, so that appropriate control or scale could be rendered. It is also possible to generate the list of currently allowed events, but be careful, this operation can be expensive if you use guards with side-effects.

State module provides a structure describing a state in the state machine definition. It stores state name along with various callbacks to run before/after leaving/entering a state. Another purpose of the module is to define a behaviour for state get/setters along with the default implementation.

Transition module gathers together all of the actions that happen around transition from the old state to the new state in response to an event.

StateMachine supports automatic validation on compile time. It makes its best effort to ensure determinism (to some degree). It checks that all used states were previously defined.