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

- old
+ new

@@ -28,19 +28,61 @@ transitions :to => :available, :from => [:out_of_stock], :guard => lambda { |product| product.in_stock > 0 } end end end +== Automatic scope generation + +`transitions` will automatically generate scopes for you if you are using AR: + +Given a model like this: + + class Order < ActiveRecord::Base + include ActiveRecord::Transitions + state_machine do + state :pick_line_items + state :picking_line_items + end + end + +you can use this feature a la: + + >> Order.pick_line_items + => [] + >> 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 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 +== 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. +*NOTE - This should be either true, a String or a Symbol* + + # This will look for an attribute called exploded_at or exploded_on (in that order) + # If present, it will be updated + event :explode, :timestamp => true do + transitions :from => :complete, :to => :exploded + end + + # This will look for an attribute named repaired_on to update upon save + event :rebuild, :timestamp => :repaired_on do + transiions :from => :exploded, :to => :rebuilt + end + + == Using with Rails This goes into your Gemfile: gem "transitions", :require => ["transitions", "active_record/transitions"] @@ -84,6 +126,6 @@ {blog post}[http://dev.netizer.pl/transitions-state-machine-for-rails-3.html] about using Transitions in ActiveRecord. == Copyright -Copyright (c) 2010 Jakub Kuźma. See LICENSE for details. +Copyright (c) 2010 Jakub Kuźma, Timo Rößner. See LICENSE for details.