0.0
No commit activity in last 3 years
No release in over 3 years
State machine used internally at Faraday.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
>= 0
>= 0
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

StatusWorkflow

Build Status

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

Faraday logo

We use status_workflow for B2C customer lifecycle optimization at Faraday.

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 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 StatusWorkflow project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Copyright

Copyright 2018 Faraday