Skip to content

ideasasylum/deepstate

Repository files navigation

DeepState

Tests Maintainability Test Coverage Dependabot Status

A Ruby gem for implementing state charts (state machines with nested states), conditional and delayed transition.



Why use DeepState?

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

Installation

Add this line to your application's Gemfile:

gem 'deepstate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deepstate

Basic Usage

Coming soon!

So what am I doing with my week’s vacation? I’m knee-deep in Ruby implementing a State Charts gem for fun

More info on State Charts: https://t.co/Y9q9a7DWNJ

It’s currently looks like this… pic.twitter.com/LL0gHbuOIE

— Jamie Lawrence (@ideasasylum) April 24, 2019
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

States

Nested States

Current States

Transitions

TBD

Hooks

TBD

Rails integration

Visualising a State Chart using XState

TBD

Development

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.

Internal Patterns

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)

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Statelychart project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

A state chart implementation for Ruby

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published