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