Home > state_machine_ext

state_machine_ext

State_machine_ext is a project mainly written in Ruby, it's free.

state_machine extensions (state groups, find transitions)

= state_machine extensions state_machine_ext is an extension of the state_machine[https://github.com/pluginaweek/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 (c) 2010 {Sphere Consulting Inc.}[http://www.sphereinc.com], released under the MIT license (see LICENSE).

Previous:IS303AAProject