README.rdoc in runcoderun-aasm-2.0.2.1 vs README.rdoc in runcoderun-aasm-2.0.2.2
- old
+ new
@@ -29,11 +29,11 @@
% sudo gem install rubyist-aasm
=== Building your own gems
% rake gem
- % sudo gem install pkg/aasm-2.0.1.gem
+ % sudo gem install pkg/aasm-2.0.2.gem
== Simple Example
Here's a quick example highlighting some of the features.
@@ -42,21 +42,53 @@
include AASM
aasm_initial_state :new
aasm_state :new
- aasm_state :read
+ aasm_state :read, :enter => :mark_thread_as_read
aasm_state :closed
aasm_event :view do
- transitions :to => :read, :from => [:new]
+ # Transitions can take an optional on_transition option to execute some logic when the event is happening.
+ # It can take a single string or symbol (denoting a method), an array of string or symbols
+ # (denoting several methods), or an inline lambda
+ transitions :to => :read, :from => [:new], :on_transition => :set_last_read_at, :guard => :user_authorized
end
aasm_event :close do
transitions :to => :closed, :from => [:read, :new]
end
+
+ # Update last_read_at timestamp when the conversation is viewed
+ def set_last_read_at
+ self.last_read_at = Time.now
+ end
+
end
+
+
+== Explanation of transitions
+
+The current state machine has the following process. If we were to call
+<tt>Conversation#view!</tt>, we would get:
+
+ state:new
+ |
+ | <-- :exit called on state[new]
+ |
+ | <-- :guard called on state[read]
+ |
+ | <-- :on_transition called on state[read]
+ |
+ | <-- aasm_current_state set to "read"
+ |
+ | <-- :success called on state[read]
+ |
+ | <-- :enter called on state[read]
+ |
+ state:read
+
= Other Stuff
Author:: Scott Barron <scott at elitists dot net>
License:: Copyright 2006, 2007, 2008 by Scott Barron.