fsmx v0.5.0 Fsmx.Struct View Source
Main module to include finite-state machine logic into your struct/schema
If no state_field
is defined, it assumes the name is :state
.
Basic usage:
defmodule MyApp.Struct do
defstruct [:state]
use Fsmx.Struct, transitions: %{}
end
You can also specify a custom state field:
defmodule MyApp.Struct do
defstruct [:my_state]
use Fsmx.Struct, state_field: :my_state, transitions: %{}
end
Or even multiple state fields, that will behave independently and have their
own transition definition, etc. In this case :state
is still used as the
default:
defmodule MyApp.Struct do
defstruct [:state, :other_state]
use Fsmx.Struct, transitions: %{}
use Fsmx.Struct, state_field: :other_state, transitions: %{}
end