Machinery.transition_to
You're seeing just the function
transition_to
, go back to Machinery module for more information.
Link to this function
transition_to(struct, state_machine_module, next_state, extra_metadata \\ None)
View SourceSpecs
transition_to(struct(), module(), Machinery.Transition.state(), map() | atom()) :: {:ok, struct()} | {:error, String.t()}
Triggers the transition of a struct to a new state, accordingly to a specific
state machine module, if it passes any existing guard functions.
It also runs any before or after callbacks and returns a tuple with
{:ok, struct}
, or {:error, "reason"}
.
Parameters
struct
: Thestruct
you want to transit to another state.state_machine_module
: The module that holds the state machine logic, where Machinery as imported.next_state
:Machinery.Transition.state/0
of the next state you want to transition to.extra_metadata
(optional): Map with extra data you might want to access in any of the Machinery functions (callbacks, guard, log, persist).
Examples
Machinery.transition_to(%User{state: :partial}, UserStateMachine, "completed")
{:ok, %User{state: "completed"}}
# Or
Machinery.transition_to(%User{state: :partial}, UserStateMachine, "completed", %{verified: true})
{:ok, %User{state: "completed"}}