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_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

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_history

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
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 idea

Copyright (c) 2010 {Sphere Consulting Inc.}[http://www.sphereinc.com], released under the MIT license (see LICENSE).