README.rdoc in transitions-0.0.18 vs README.rdoc in transitions-0.1.0
- old
+ new
@@ -1,8 +1,8 @@
= Travis Build Status
-{<img src="https://secure.travis-ci.org/troessner/transitions.png"/>}[http://travis-ci.org/troessner/transitions]
+{<img src="https://secure.travis-ci.org/troessner/transitions.png?branch=master"/>}[http://travis-ci.org/troessner/transitions]
= Synopsis
<tt>transitions</tt> is a ruby state machine implementation.
@@ -22,14 +22,12 @@
gem install transitions
= Using transitions
- require 'transitions'
-
class Product
- include Transitions
+ include ActiveModel::Transitions
state_machine do
state :available # first one is initial state
state :out_of_stock, :exit => :exit_out_of_stock
state :discontinued, :enter => lambda { |product| product.cancel_orders }
@@ -44,10 +42,17 @@
transitions :to => :available, :from => [:out_of_stock], :guard => lambda { |product| product.in_stock > 0 }
end
end
end
+In this example we assume that you are in a rails project using Bundler, which would automitcally require `transitions`.
+If this is not the case for you you have to add
+
+ require 'transitions'
+
+whereever you load your dependencies in your application.
+
= Features
== Events
When you declare an event, say <tt>discontinue</tt>, two methods are declared for
@@ -117,10 +122,23 @@
# This will look for an attribute named repaired_on to update upon save
event :rebuild, :timestamp => :repaired_on do
transitions :from => :exploded, :to => :rebuilt
end
+== `event_fired` and `event_failed`
+
+In case you define `event_fired` and / or `event_failed`, `transitions` will use those callbacks correspondingly.
+You can use those callbacks like this:
+
+ def event_fired(current_state, new_state, event)
+ MyLogger.info "Event fired #{event.inspect}"
+ end
+
+ def event_failed(event)
+ MyLogger.warn "Event failed #{event.inspect}"
+ end
+
== Listing all the available states
You can easily get a listing of all available states:
Order.available_states # Uses the <tt>default</tt> state machine
@@ -131,12 +149,9 @@
Order.available_states(:your_machine)
= Documentation, Guides & Examples
- {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
Copyright (c) 2010 Jakub Kuźma, Timo Rößner. See LICENSE for details.