ash_state_machine/lib/info.ex
James Harton cf2bef0e38
feat: Add next_state builtin change. (#6)
When there is only a single possible next state that can be transitioned into, we can automatically transition into that state.
2023-09-08 13:35:51 +12:00

17 lines
700 B
Elixir

defmodule AshStateMachine.Info do
@moduledoc "Introspection helpers for `AshStateMachine`"
use Spark.InfoGenerator, extension: AshStateMachine, sections: [:state_machine]
@spec state_machine_transitions(Ash.Resource.t() | map(), name :: atom) ::
list(AshStateMachine.Transition.t())
def state_machine_transitions(resource_or_dsl, name) do
resource_or_dsl
|> state_machine_transitions()
|> Enum.filter(&(&1.action == :* || &1.action == name))
end
@spec state_machine_all_states(Ash.Resource.t() | map()) :: list(atom)
def state_machine_all_states(resource_or_dsl) do
Spark.Dsl.Extension.get_persisted(resource_or_dsl, :all_state_machine_states, [])
end
end