From afe3460863885ade5f442720785baaf9446a02d8 Mon Sep 17 00:00:00 2001 From: Daniel Lo Date: Tue, 7 Oct 2014 12:50:20 -0700 Subject: [PATCH] Added a section for transitions I was a bit confused about having multiple transitions. After figuring it out, I added this section. --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index cc6beb7..53ae5ef 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,38 @@ If you want to provide guards for all transitions within an event, you can use e end ``` +### Transitions + +In the event of having multiple transitions for an event, the first transition that successfully completes will stop other transitions in the same event from being processed. + +```ruby +require 'aasm' + +class Job + include AASM + + aasm do + state :stage1, :initial => true + state :stage2 + state :stage3 + state :completed + + event :stage1_completed do + transitions from: :stage1, to: :stage3, guard: :stage2_completed? + transitions from: :stage1, to: :stage2 + end + end + + def stage2_completed? + true + end +end + +job = Job.new +job.stage1_completed +job.aasm.current_state # stage3 +``` + ### ActiveRecord AASM comes with support for ActiveRecord and allows automatical persisting of the object's