Popularity
2.2
Growing
Activity
0.0
Stable
9
3
1
Monthly Downloads: 0
Programming language: Elixir
License: MIT License
state_mc alternatives and similar packages
Based on the "State Machines" category.
Alternatively, view state_mc alternatives based on common mentions on social networks and blogs.
-
gen_state_machine
An idiomatic Elixir wrapper for gen_statem in OTP 19 (and above). -
Gearbox
⚙️ Gearbox is a functional state machine with an easy-to-use API, inspired by both Fsm and Machinery
TestGPT | Generating meaningful tests for busy devs
Get non-trivial tests (and trivial, too!) suggested right inside your IDE, so you can code smart, create more value, and stay confident when you push.
Promo
codium.ai
Do you think we are missing an alternative of state_mc or a related project?
README
State Machine for Ecto
State machine pattern in Ecto.
Installation
The package can be installed as:
Add
state_mc
to your list of dependencies inmix.exs
:def deps do [{:state_mc, "~> 0.1.0"}] end
How to use?
Example:
defmodule Example.User do
use Example.Web, :model
import StateMc.EctoSm
schema "users" do
field :state, :string, default: "waiting"
end
statemc :state do
defstate [:waiting, :approved, :rejected]
defevent :approve, %{from: [:waiting, :rejected], to: :approved}, fn(changeset) ->
changeset
|> Example.Repo.update()
end
defevent :reject, %{from: [:waiting, :approved], to: :rejected}, fn(changeset) ->
changeset
|> Example.Repo.update()
end
end
end
How to run?
user = Example.Repo.get(Example.User, 1)
Example.User.current_state(user) # => get current state
Example.User.can_approve?(user) # => check event approve
Example.User.can_reject?(user) # => check event reject
Example.User.approve(user) # => call event approve to change state to approved
Example.User.reject(user) # => call event reject to change state to rejected