Skip to content
/ aasm Public

The finite state machine implementations for Elixir.

Notifications You must be signed in to change notification settings

zven21/aasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AASM

The finite state machine implementations for Elixir.

Table of contents

Getting started

  • The package can be installed by adding aasm to your list of dependencies in mix.exs:
def deps do
  [
    {:aasm, "~> 0.2.0"}
  ]
end

Examples

defmodule Dummy.Order do
  @moduledoc """
  Order model
  """

  use Ecto.Schema
  import AASM

  aasm :state do
    state(~w(state_created state_assigned state_finished state_closed)a)

    event(:handle_assigned, %{from: ~w(state_created)a, to: :state_assigned}, fn changeset ->
      changeset
    end)

    event(:handle_finished, %{from: ~w(state_assigned)a, to: :state_finished}, fn changeset ->
      changeset
    end)

    event(
      :handle_closed,
      %{from: ~w(state_created state_assigned state_finished)a, to: :state_closed},
      fn changeset -> changeset end
    )
  end

  schema "orders" do
    field(:state, :string)
  end
end

TODO

  • Support multi db column.
  • Add before_event.
  • Initial value

Contributing

Bug report or pull request are welcome.

Make a pull request

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Please write unit test with your code if necessary.

License

The gem is available as open source under the terms of the MIT License.

Credits

About

The finite state machine implementations for Elixir.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages