Skip to content

Feature: Add transition_to!/3~4  #90

@kyleboe

Description

@kyleboe

Similar to other ! suffixed functions, the thought would be to either return the transformed struct or raise an error. The goal of this change would be to allow the transition_to! call to be chained in a pipeline.

Given:

defmodule MyStateMachine do
  use Machinery,
    states: ~w(pending completed),
    transitions: %{"pending" => ["completed"]}
end

defmodule MyStruct do
  defstruct [:state]
end

The spec for the function(s) may look something like this:

Machinery.transition_to!(%MyStruct{state: "pending"}, MyStateMachine, "completed")
# %MyStruct{state: "completed"}

Machinery.transition_to!(%MyStruct{state: "completed"}, MyStateMachine, "pending")
# raise Machinery.Errors.UndeclaredTransition

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions