Project

control

0.0
No release in over 3 years
Low commit activity in last 3 years
State Machine integrated with ActiveRecord
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Workflow engine

Build Status Code Climate

Premises

  • ActiveRecord
  • Each state is a separate object.

Features

  • State can be as rich in functionality was wanted.
  • No data is ever lost. History is always saved.
  • It is possible to track every single transition done in the workflow.
  • Advancing a state is as easy as creating a state object and calling "save".
  • Can transition to same state.
  • Minimal code to define workflow and states.

Simple example for a Bulb with two states:


class Bulb < ActiveRecord::Base
  include Control::Workflow
  
  has_many :ons
  has_many :offs
end

class On < ActiveRecord::Base
  include Control::State
	
  belongs_to :bulb
end

class Off < ActiveRecord::Base
  include Control::State

  belongs_to :bulb
  next_states :on # optional, to constrain possible next states, can also specify :none to make a state final
end

def example
  my_bulb = Bulb.new
  
  my_on = On.new do |o|
    o.bulb = my_bulb
  end
  
  my_off = Off.new do |o|
    o.bulb = my_bulb
  end
  
  # Check possible states for my bulb. (On, Off)
  my_bulb.states
  
  # Transitions the bulb to the "On" state
  my_on.save
  
  # Transitions the bulb to the "Off" state
  my_off.save
  
  # Every transition is recorded. (On -> Off)
  my_bulb.transitions
  
  # Bulb knows which state is current. (Off)
  my_bulb.current_state
end

Installing:

  1. Add control gem to gemfile.
gem 'control'

or

gem 'control', :git => 'git://github.com/zeto/control.git' # Edge
  1. Generate tables (run rake db:migrate after)
$ rails generate control_install

Testing the gem:


$ bundle
$ rake