README.rdoc in transitions-0.0.11 vs README.rdoc in transitions-0.0.12

- old
+ new

@@ -1,13 +1,13 @@ +== Travis Build Status {<img src="https://secure.travis-ci.org/troessner/transitions.png"/>}[http://travis-ci.org/troessner/transitions] + = What is transitions? transitions is a ruby state machine implementation based on Rick Olson’s ActiveModel::StateMachine. It was extracted from ActiveModel and turned into a gem when it got the axe in commit {db49c706b}[http://github.com/rails/rails/commit/db49c706b62e7ea2ab93f05399dbfddf5087ee0c]. -I really encourage you to try {state_machine}[https://github.com/pluginaweek/state_machine] before using this gem. Currently I have no time to maintain the gem, if you want to add some new features - contact with me. - == Quick Example require 'transitions' class Product @@ -30,17 +30,17 @@ end end == Automatic scope generation -`transitions` will automatically generate scopes for you if you are using AR: +`transitions` will automatically generate scopes for you if you are using ActiveRecord and tell it to do so via the `auto_scopes` option: Given a model like this: class Order < ActiveRecord::Base include ActiveRecord::Transitions - state_machine do + state_machine :auto_scopes => true do state :pick_line_items state :picking_line_items end end @@ -51,19 +51,28 @@ >> Order.create! => #<Order id: 3, state: "pick_line_items", description: nil, created_at: "2011-08-23 15:48:46", updated_at: "2011-08-23 15:48:46"> >> Order.pick_line_items => [#<Order id: 3, state: "pick_line_items", description: nil, created_at: "2011-08-23 15:48:46", updated_at: "2011-08-23 15:48:46">] -== Using on_transition +== Using `on_transition` Each event definition takes an optional "on_transition" argument, which allows you to execute methods on transition. You can pass in a Symbol, a String, a Proc or an Array containing method names as Symbol or String like this: event :discontinue do transitions :to => :discontinued, :from => [:available, :out_of_stock], :on_transition => [:do_discontinue, :notify_clerk] end +== Using `success` + +In case you need to trigger a method call after a successful transition you can use `success`: + + event :discontinue, :success => :notfiy_admin do + transitions :to => :discontinued, :from => [:available, :out_of_stock] + end + + == Timestamps If you'd like to note the time of a state change, Transitions comes with timestamps free! To activate them, simply pass the :timestamp option to the event definition with a value of either true or the name of the timestamp column. @@ -119,10 +128,10 @@ <tt>write_state_without_persistence</tt> on successful transition, but only the bang(!)-version will call <tt>write_state</tt>. == Documentation, Guides & Examples -- {Online API Documentation}[http://rdoc.info/github/qoobaa/transitions/master/Transitions] +- {Online API Documentation}[http://rdoc.info/github/troessner/transitions/master/Transitions] - Krzysiek Heród (aka {Netizer}[http://github.com/netizer]) wrote a nice {blog post}[http://dev.netizer.pl/transitions-state-machine-for-rails-3.html] about using Transitions in ActiveRecord. == Copyright