State Machines
We use AASM to add finite state machines to our Ruby classes. AASM ("acts as state machine") is a generic library that supports many ORMs, but at Thanx we primarily use this for ActiveRecord models.
#
Examplesclass Job include AASM
aasm do state :sleeping, initial: true state :running, :cleaning
event :run do transitions from: :sleeping, to: :running end
event :clean do transitions from: :running, to: :cleaning end
event :sleep do transitions from: [:running, :cleaning], to: :sleeping end endend