defmodule Understated do defmacro __using__(_options) do quote do import Understated.Machine import Understated.State import Understated.Transition import Understated.Entry Module.register_attribute(__MODULE__, :transitions, accumulate: true) Module.register_attribute(__MODULE__, :states, accumulate: true) Module.register_attribute(__MODULE__, :current_state, accumulate: false) @current_state "" @before_compile unquote(__MODULE__) end end defmacro __before_compile__(_env) do quote do def valid_states() do @states |> Enum.reverse() end def before_event(machine, _from, _to), do: machine def after_event(machine, _from, _to), do: machine def enter_state(machine, _from_state), do: machine def trigger(machine, _to_state), do: machine defp apply_state(machine, _state), do: machine end end end