aasm
aasm.cr 
Easy to use finite state machine for Crystal classes.
Usage
Adding a state machine is as simple as including AASM
module and overwriting act_as_state_machine
method
where you can start defining states and events with their transitions:
class Transaction
include AASM
def act_as_state_machine
aasm.state :pending, initial: true
aasm.state :active, enter: -> { puts "Just got activated" }
aasm.state :completed
aasm.event :activate do |e|
e.transitions from: :pending, to: :active
end
aasm.event :complete do |e|
e.transitions from: :active, to: :completed
end
end
end
t = Transaction.new.tap &.act_as_state_machine
t.state #=> :pending
t.next_state #=> :active
t.fire :activate # Just got activated
t.state #=> :active
t.next_state #=> :completed
Contributing
- Fork it ( https://github.com/veelenga/aasm/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request