ash_state_machine/lib/info.ex

18 lines
700 B
Elixir
Raw Normal View History

defmodule AshStateMachine.Info do
@moduledoc "Introspection helpers for `AshStateMachine`"
use Spark.InfoGenerator, extension: AshStateMachine, sections: [:state_machine]
2023-04-22 05:43:36 +12:00
@spec state_machine_transitions(Ash.Resource.t() | map(), name :: atom) ::
list(AshStateMachine.Transition.t())
def state_machine_transitions(resource_or_dsl, name) do
2023-04-22 07:25:39 +12:00
resource_or_dsl
|> state_machine_transitions()
|> Enum.filter(&(&1.action == :* || &1.action == name))
2023-04-22 07:25:39 +12:00
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, [])
2023-04-22 05:43:36 +12:00
end
end