https://github.com/jamesmoriarty/mini-aasm
A State Machine library intended to be compatible with lightweight implementations of the Ruby language using 100LOC and only standard libraries.
https://github.com/jamesmoriarty/mini-aasm
domain-specific-language dragonruby mruby ruby state-machine tinycode
Last synced: 4 months ago
JSON representation
A State Machine library intended to be compatible with lightweight implementations of the Ruby language using 100LOC and only standard libraries.
- Host: GitHub
- URL: https://github.com/jamesmoriarty/mini-aasm
- Owner: jamesmoriarty
- Created: 2023-01-24T03:38:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-28T07:04:17.000Z (over 2 years ago)
- Last Synced: 2025-03-01T08:23:35.735Z (5 months ago)
- Topics: domain-specific-language, dragonruby, mruby, ruby, state-machine, tinycode
- Language: Ruby
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MiniAASM
![Gem Version][3] ![Gem][1] ![Build Status][2]
A [finite-state machine](https://en.wikipedia.org/wiki/Finite-state_machine) library intended to be compatible with [lightweight implementations](https://github.com/mruby/mruby) of the Ruby language using 100LOC and only standard libraries. Inspired by [Heroku Postgres finite-state machine](https://www.citusdata.com/blog/2016/08/12/state-machines-to-run-databases/).
## Usage
```ruby
class TransmissionJob
include MiniAASMaasm do
state :transmitting, initial: true
state :waiting_confirmation
state :terminatedevent :work_succeeded do
transitions from: :waiting_confirmation, to: :transmitting
transitions from: :transmitting, to: :waiting_confirmation, guard: %i[hold?]
endevent :work_failed do
transitions from: %i[transmitting waiting_confirmation], to: :terminated
end
end# ...
end
```_See [test/support/transmission_job.rb](test/support/transmission_job.rb)._
```ruby
> job = TransmissionJob.new
=> #
> job.current_state
=> :transmitting
job.work_succeeded!
=> :waiting_confirmation
> job.work_succeeded!
=> :transmitting
> job.work_failed!
=> :terminated
```
## InstallationAdd this line to your application's Gemfile:
```ruby
gem 'mini-aasm'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install mini-aasm
## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jamesmoriarty/mini-aasm.
[1]: https://img.shields.io/gem/dt/mini-aasm
[2]: https://github.com/jamesmoriarty/mini-aasm/workflows/Continuous%20Integration/badge.svg?branch=main
[3]: https://img.shields.io/gem/v/mini-aasm