AASM adds explicit states, events, guards, and callbacks to Ruby objects, with adapters for ActiveRecord and other persistence layers.
Overview
AASM is a Ruby library for defining finite state machines on plain classes or ORM-backed models. It grew from the acts_as_state_machine plugin but now supports many persistence backends beyond ActiveRecord.
You declare states and events, wire transitions, and gain instance methods to query state or fire events. Callbacks can run around guards, transitions, and lifecycle steps, with optional error handlers and non-whiny boolean returns.
ActiveRecord integration can persist state columns, honor bang methods, timestamps on state entry, and enums. Additional adapters cover Sequel, Mongoid, Dynamoid, NoBrainer, Redis::Objects, and related stores.
Multiple state machines per class are supported with namespacing to avoid method clashes. Scopes, transactions, after_commit hooks, and inspection helpers round out typical Rails workflow needs.
Key features
- States, events, and transitions
- Guards and callbacks
- ActiveRecord persistence
- Multiple ORM adapters
- Multiple machines per class
- Automatic scopes
- Transaction-aware callbacks
- Enum column support
Use cases
- Workflow state on Rails models
- Order or job lifecycles
- Non-ActiveRecord Ruby classes
- Guarding invalid transitions
- Audit-friendly state logs