A Ruby gem for implementing state charts (state machines with nested states), conditional and delayed transition.
- Why use DeepState?
- Installation
- Basic Usage
- States
- Transitions
- Hooks
- Rails integration
- Visualising a State Chart using XState
- Development
- Contributing
- License
- Code of Conduct
There are already plenty of great Ruby gems for modelling state machines. Maybe you should use one of them:
AASM is a old favourite with a lot of functionality
Workflow is my go-to solution for simple state machines in Rails with a nice DSL and
Finite Machine is a nice library that separates the machine itself from the ActiveRecord model.
DeepState uses some of the best features from those libraries but with the added super-power of hierarchical states. Specifically, State Charts.
Have you ever used multiple state machines to model a system?
Or, wanted to make a transition conditional?
Or, needed to delay a transition?
Or, modelled a pseudo-state as being in A, B, or C states?
Yeah? Well read on because DeepState and state charts might be just what you need.
The main features are:
- Nested/hierarchical states (state charts)
- Multiple "current" states
- Entry/exit hooks
- Conditional transitions (coming soon)
- Delayed transitions (coming soon)
- Rails-integration
Add this line to your application's Gemfile:
gem 'deepstate'
And then execute:
$ bundle
Or install it yourself as:
$ gem install deepstate
Coming soon!
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>So what am I doing with my week’s vacation? I’m knee-deep in Ruby implementing a State Charts gem for fun
— Jamie Lawrence (@ideasasylum) April 24, 2019
More info on State Charts: https://t.co/Y9q9a7DWNJ
It’s currently looks like this… pic.twitter.com/LL0gHbuOIE
TBD
TBD
TBD
After checking out the repo, run bundle install
to install dependencies. Then, run bundle exec rspec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
DeepState uses the visitor pattern to build up information from the StateDefinition
structure. A visitor object that responds to visit
can be passed to StateDefinition#visit
and that object's visit
method will be invoked for every state as a depth-first search through the hierarchy. This can be used to collect information (like MachineVisitor
) or generate an export (like XStateVisitor
)
Bug reports and pull requests are welcome on GitHub at https://github.com/ideasasylum/deepstate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Statelychart project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.