A minimal finite state machine implementation for Ruby with less than 50 lines of code.
MicroMachine is a minimal finite state machine implementation for Ruby that provides essential state transition functionality in under 50 lines of code. It solves the problem of managing state changes in Ruby applications without the complexity of larger FSM libraries, offering a clean, composable approach to state management.
Ruby developers who need lightweight state management in their applications, particularly those working with models that require state transitions like order processing, user workflows, or approval systems.
Developers choose MicroMachine for its extreme simplicity and minimal footprint—it provides only the essential FSM functionality without complex DSLs or dependencies, making it easy to understand, integrate, and maintain.
Minimal Finite State Machine
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
At under 50 lines, it eliminates bloat and dependencies, making it easy to audit and understand, as highlighted in the README's emphasis on providing only essential FSM functionality.
It uses plain Ruby hashes and methods like `when` for transitions, allowing flexible instantiation within models without mixins, as demonstrated in the ActiveRecord integration examples.
Supports callbacks on specific states or any transition with payload passing, enabling custom actions like persisting state changes, as shown in the `on(:any)` example.
Provides methods like `trigger?` for safe state checking and `events` for listing all possible transitions, aiding in debugging and dynamic workflows.
Lacks built-in persistence; developers must manually sync state to databases, as admitted in the README's verbose ActiveRecord examples requiring callbacks or before_save hooks.
Missing common FSM features like conditional transitions, state guards, or event guards, forcing custom logic outside the library for complex scenarios.
Defining transitions via hash assignments can become cumbersome for large state machines compared to DSL-based alternatives, increasing boilerplate code.