https://github.com/faradayio/status_workflow_ruby
State machine used internally at Faraday (ruby).
https://github.com/faradayio/status_workflow_ruby
Last synced: 25 days ago
JSON representation
State machine used internally at Faraday (ruby).
- Host: GitHub
- URL: https://github.com/faradayio/status_workflow_ruby
- Owner: faradayio
- License: mit
- Created: 2018-09-21T21:28:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T17:34:12.000Z (over 7 years ago)
- Last Synced: 2024-04-24T19:31:59.935Z (about 2 years ago)
- Language: Ruby
- Size: 35.2 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# StatusWorkflow
[](https://travis-ci.org/faradayio/status_workflow_ruby)
Basic state machine using Redis for locking.
## Usage
```
require 'redis'
StatusWorkflow.redis = Redis.new
```
You need an object that has `status`, `status_changed_at`, and `status_error`.
Expects but does not require ActiveRecord (you just have to respond to `#reload`, `#id`, and `#update_columns`)
```
class Pet < ActiveRecord::Base
before_create do
self.status ||= 'sleep'
end
include StatusWorkflow
status_workflow(
sleep: [:fed],
fed: [:sleep, :run],
run: [:sleep],
)
end
```
where
```
sleep: [:fed],
fed: [:sleep, :run],
run: [:sleep],
```
means:
* from sleep, i can go to fed
* from fed, i can go to sleep or run
* from run, i can go to sleep
If you want >1 status, you do
```
include StatusWorkflow
status_workflow(
nil => {
sleep: [:feeding],
feeding: [:fed],
fed: [:sleep, :run],
run: [:sleep],
},
alt: {
sleep2: [:feeding2],
feeding2: [:fed2],
fed2: [:sleep2, :run2],
run2: [:sleep2],
}
)
```
You need an object that has `alt_status`, `alt_status_changed_at`, and `alt_status_error`.
## Sponsor
We use [`status_workflow`](https://github.com/faradayio/status_workflow_ruby) for [B2C customer lifecycle optimization at Faraday](https://www.faraday.io).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/status_workflow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the StatusWorkflow project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/status_workflow/blob/master/CODE_OF_CONDUCT.md).
## Copyright
Copyright 2018 Faraday