Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/spheresoftware/state_machine_ext
- Owner: SphereSoftware
- Created: 2010-11-26T13:45:32.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2011-02-11T08:54:40.000Z (almost 14 years ago)
- Last Synced: 2024-10-29T05:19:42.354Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 88.9 KB
- Stars: 3
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
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 TeamCopyright (c) 2010 {Sphere Consulting Inc.}[http://www.sphereinc.com], released under the MIT license (see LICENSE).