AASM is a Ruby library for adding finite state machines to plain Ruby classes and ORM models like ActiveRecord and Mongoid.
AASM is a Ruby library for adding finite state machines to Ruby classes. It allows developers to define states, events, and transitions in a declarative way, helping to model business workflows and manage object lifecycles. It supports various ORMs like ActiveRecord and Mongoid, making it versatile for different Ruby applications.
Ruby developers building applications with complex state transitions, such as e-commerce order processing, content publishing workflows, or user lifecycle management. It's particularly useful for teams using ActiveRecord, Mongoid, or other supported ORMs.
AASM provides a clean, ORM-agnostic DSL for state machines with extensive features like callbacks, guards, and transaction support. Its flexibility and deep integration with popular Ruby ORMs make it a preferred choice over simpler state machine implementations.
AASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid, NoBrainer, Dynamoid)
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses a clean, readable syntax with aasm blocks to define states and events, making complex workflows straightforward to implement and maintain, as shown in the Job class example.
Seamlessly works with ActiveRecord, Mongoid, Sequel, Dynamoid, and others, providing automatic persistence, scopes, and transaction hooks without custom adapters.
Supports fine-grained control with before, after, error, and ensure callbacks for events and transitions, allowing custom logic injection at every lifecycle stage.
Includes RSpec and Minitest matchers like transition_from and have_state, simplifying test creation for state transitions without extra setup.
Major version upgrades (e.g., v3 to v4) require careful migration with documented changes, risking compatibility issues in existing codebases, as noted in the separate upgrade guide.
Some ORMs like Sequel lack full feature parity—for instance, automatic scopes aren't yet implemented, limiting functionality compared to ActiveRecord-centric use.
Handling multiple state machines in one class can lead to naming conflicts and increased boilerplate, requiring explicit column management and namespaces to avoid overrides.