mirror of
https://github.com/ash-project/ash_state_machine.git
synced 2024-09-21 22:03:12 +12:00
43 lines
737 B
Elixir
43 lines
737 B
Elixir
|
defmodule NextStateMachine do
|
||
|
@moduledoc false
|
||
|
use Ash.Resource,
|
||
|
domain: Domain,
|
||
|
extensions: [AshStateMachine]
|
||
|
|
||
|
state_machine do
|
||
|
initial_states [:a]
|
||
|
default_initial_state :a
|
||
|
|
||
|
transitions do
|
||
|
transition :next, from: :a, to: :b
|
||
|
transition :next, from: :b, to: :c
|
||
|
transition :next, from: :b, to: :d
|
||
|
end
|
||
|
end
|
||
|
|
||
|
attributes do
|
||
|
uuid_primary_key :id
|
||
|
|
||
|
attribute :state, :atom do
|
||
|
allow_nil? false
|
||
|
public? true
|
||
|
constraints one_of: [:a, :b, :c, :d]
|
||
|
default :a
|
||
|
end
|
||
|
end
|
||
|
|
||
|
actions do
|
||
|
default_accept :*
|
||
|
defaults [:read, :create]
|
||
|
|
||
|
update :next do
|
||
|
change next_state()
|
||
|
end
|
||
|
end
|
||
|
|
||
|
code_interface do
|
||
|
define :create
|
||
|
define :next
|
||
|
end
|
||
|
end
|