Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/spheresoftware/state_machine_ext

state_machine extensions (state groups, find transitions)
https://github.com/spheresoftware/state_machine_ext

Last synced: about 1 month ago
JSON representation

state_machine extensions (state groups, find transitions)

Awesome Lists containing this project

README

        

= 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).