No commit activity in last 3 years
No release in over 3 years
state_machine extensions(state groups, find transitions)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

state_machine extensions¶ ↑

state_machine_ext is an extension of the state_machine gem.

Install¶ ↑

gem install state_machine_ext

Usage¶ ↑

This gem adds state groups functionality and method to find all possible transitions from a state. Below is an example of the features offered:

Class definition¶ ↑

class Order
  state_machine :initial => :not_selected do
    event :choose do
      transition :not_selected => :selected
    end
    event :add_to_basket do
      transition :selected => :in_basket
    end
    event :pay do
      transition :in_basket => :paid
    end
    event :to_send do
      transition :paid => :sent
    end

    #initialize groups of the states
    group :not_paid do
      state :not_selected
      state :selected
      state :in_basket
    end
    group :in_progress do
      state :paid, :sent
    end
  end
end

Using extensions¶ ↑

order = Order.new
# returns the array of all the states which we can reach from the current one
order.state_all_transitions                #=> [:sent, :paid, :in_basket, :selected]
# same for the particular state
order.state_all_transitions(:in_basket)    #=> [:sent, :paid]
# check whether a group includes some state
order.group(:not_paid).include?(:selected) #=> true
# find groups to which belongs a state
order.find_group(:paid)                    #=> [:in_progress]

Credits¶ ↑

Project Team¶ ↑

  • Sphere Consulting Inc Development Team

Copyright © 2010 Sphere Consulting Inc., released under the MIT license (see LICENSE).