SuperState
==========
Super Simple state machine for Ruby and Rails
(designed for ActiveRecord, but hopefully easily extended to any ActiveModel)
Example
=======
a simple multi-state model
class MyModel < ActiveRecord::Base
include SuperState
super_state :pending, :initial => true
super_state :processing
super_state :completed
super_state :failed
super_state_group :outstanding, ["pending", "processing"]
# first part of a two stage transition
# eg.
# def process
# start_processing!
# do_the_stuff
# complete_processing!
# end
#
state_transition :start_processing, :pending => :processing
# second part of a two stage transition
state_transition :complete_processing, :processing => :completed
# transition direct from pending to complete
state_transition :complete, :pending => :completed
# failed to process
state_transition :fail, :processing => :failed
# back to processing
state_transition :restart, :failed => :processing
end
this is actually already shipped as a magic mixin
class MyClass < ActiveRecord::Base
include SuperState::CommonStates
end
we can also take arguments in our transitions
class Loan < ActiveRecord::Base
include SuperState
super_state :requested, :initial => true
super_state :disbursed
state_transition :disburse, :requested => :disbursed do |params|
self.disbursed_amount = params[:amount]
self.disbursed_date = params[:disbursed_date]
end
end
Copyright (c) 2010 [Matthew Rudy Jacobs], released under the MIT license
Project
super_state
Super Simple State Machine
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
Development
Dependencies
Project Readme