Machinist.transitions
You're seeing just the macro
transitions
, go back to Machinist module for more information.
Defines a block of transitions.
By default transitions/1
expects the module using Machinist
has a struct
defined with a state
attribute
transitions do
# ...
end
Defines a block of transitions for a specific struct or defines a block of
transitions just passing the attr
option to define the attribute holding the state
Examples
A Candidate being handled by two different versions of a SelectionProcess
defmodule Candidate do
defstruct state: :new
end
defmodule SelectionProcess.V1 do
use Machinist
transitions Candidate do
from :new, to: :registered, event: "register"
end
end
defmodule SelectionProcess.V2 do
use Machinist
transitions Candidate do
from :new, to: :enrolled, event: "enroll"
end
end
Providing the attr
option to define the attribute holding the state
defmodule Candidate do
defstruct candidate_state: :new
use Machinist
transitions attr: :candidate_state do
from :new, to: :registered, event: "register"
end
end
Defines a block of transitions for a specific struct with attr
option
defining the attribute holding the state
transitions Candidate, attr: :candidate_state do
# ...
end