title: statemachine, conditional transitions
body: <p>I'm currently using <a href="http://github.com/ryan-allen/workflow" rel="nofollow noreferrer">Workflow</a>.</p>
  
  <pre><code>class Link &lt; ActiveRecord::Base
    include Workflow
    workflow do
      state :new do
        event :process, :transitions_to =&gt; :checking #checking http_response_code &amp; content_type
      end
  
      state :checking do
        event :process, :transitions_to =&gt; :fetching_links # fetching all links
      end
      state :fetching_links do
        event :process, :transitions_to =&gt; :checking #ready for next check
      end
    end
  end
  </code></pre>
  
  <p>Now, I can do:</p>
  
  <pre><code>l = Link.new
  l.process!
  l.process!
  l.process!
  l.process!
  # n times l.process! (in a loop, or cron job for example)
  </code></pre>
  
  <p>But it can happens, some link will not respond or give me an invalid response durning the checking process.</p>
  
  <p>How I can conditionally switch to another state ? </p>
  
  <p>I mean something like this:</p>
  
  <pre><code>class Link &lt; ActiveRecord::Base
    include Workflow
    workflow do
      state :new do
        event :process, :transitions_to =&gt; :checking #checking http_response_code &amp; content_type
      end
  
      state :checking do
        event :process, :transitions_to =&gt; :fetching_links # if all is fine
        event :process, :transitions_to =&gt; :failded # if something goes wrong
      end
      state :fetching_links do
        event :process, :transitions_to =&gt; :checking #ready for next check
      end
    end
  end
  </code></pre>