Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spheresoftware/state_machine_history
state_machine history for Ruby On Rails applications
https://github.com/spheresoftware/state_machine_history
Last synced: about 1 month ago
JSON representation
state_machine history for Ruby On Rails applications
- Host: GitHub
- URL: https://github.com/spheresoftware/state_machine_history
- Owner: SphereSoftware
- Created: 2010-12-15T09:12:13.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2010-12-21T12:50:25.000Z (about 14 years ago)
- Last Synced: 2024-04-20T10:04:20.343Z (9 months ago)
- Language: Ruby
- Homepage:
- Size: 82 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
= state_machine_history
state_machine_history is an extension of the state_machine[https://github.com/pluginaweek/state_machine] gem,
that logs transitions between states and allows to check if a state was visited earlier.== Install
gem install state_machine_history=== Ruby On Rails 2.x
Add the gem dependency to environment.rb:
...
config.gem 'state_machine_history'
...
Generate the migration:
script/generate state_machine_history_2 create_machine_history
Run the migration
rake db:migrate=== Ruby On Rails 3
In Gemfile:
gem 'state_machine_history'
Generate the migration:
rails generate state_machine_history create_machine_history
Run the migration:
rake db:migrate== Usage
This gem adds logging function to the state_machine gem.
Sample:=== Class definition
class Order
state_machine :initial => :not_selected do
# Switch on state machine logging
track_historyevent :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
end
end=== Using extensions
order = Order.new
# Perform transition (state change is logged)
order.choose
# Find whether order has visited not_selected state before selected one
order.was_there?(:not_selected, :selected) #=> true
# Find whether order has visited not_selected state before the current one
order.was_there?(:not_selected) #=> true== Credits
=== Project Team
* Mykhaylo Sorochan - Project Manager
* Dmitriy Landberg - Software Developer
* Nataliya Shatokhina - Tester
* Sergey Mostovoy - Extension ideaCopyright (c) 2010 {Sphere Consulting Inc.}[http://www.sphereinc.com], released under the MIT license (see LICENSE).