state_machine_history is an extension of the state_machine gem, that logs transitions between states and allows to check if a state was visited earlier.
gem install state_machine_history
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
In Gemfile:
gem 'state_machine_history'
Generate the migration:
rails generate state_machine_history create_machine_history
Run the migration:
rake db:migrate
This gem adds logging function to the state_machine gem. Sample:
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
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
-
Mykhaylo Sorochan - Project Manager
-
Dmitriy Landberg - Software Developer
-
Nataliya Shatokhina - Tester
-
Sergey Mostovoy - Extension idea
Copyright © 2010 Sphere Consulting Inc., released under the MIT license (see LICENSE).