A minimal Ruby finite state machine with a straightforward and intuitive syntax for modeling states, transitions, and callbacks.
FiniteMachine is a Ruby library for implementing finite state machines. It allows developers to model states, transitions, and callbacks using a clean, intuitive DSL. It solves the problem of managing complex stateful logic in Ruby applications by providing a structured yet flexible approach.
Ruby developers building applications with stateful behavior, such as workflow engines, UI state management, or process automation systems.
Developers choose FiniteMachine for its minimal design, straightforward syntax, and powerful features like conditional transitions and comprehensive callbacks, all without the bloat of larger state machine libraries.
A minimal finite state machine with a straightforward syntax.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The library uses a natural language DSL, such as `event :ready, :red => :yellow`, making state definitions readable and concise, as shown in the usage examples.
Supports before, after, enter, exit, and transition callbacks with flexible parameters, allowing fine-grained control over state changes, detailed in section 4.
Explicitly designed to be safe in concurrent environments, making it suitable for multi-threaded Ruby applications, as mentioned in the features list.
Can be used as a standalone object or integrated with existing Ruby classes and ActiveRecord models, demonstrated in sections 6 and 7 with target context.
By default, event names are converted to methods, which can conflict with existing methods like `:fail` or `:trigger`, requiring `auto_methods: false` to avoid, as noted in section 2.7.1.
When integrating with databases like ActiveRecord, developers must manually handle state saving using callbacks and `restore!`, adding boilerplate code, as shown in section 7.2.
Lacks graphical debugging tools or visualization for state machines, which might be needed for complex logic analysis, compared to some other state machine libraries.