def transition_for(object, requirements = {})
      requirements.assert_valid_keys(:from, :to, :guard)
      requirements[:from] = machine.states.match!(object).name unless custom_from_state = requirements.include?(:from)

      branches.each do |branch|
        if match = branch.match(object, requirements)
          # Branch allows for the transition to occur
          from = requirements[:from]
          to = if match[:to].is_a?(LoopbackMatcher)
                 from
               else
                 values = requirements.include?(:to) ? [requirements[:to]].flatten : [from] | machine.states.map { |state| state.name }

                 match[:to].filter(values).first
               end

          return Transition.new(object, machine, name, from, to, !custom_from_state)
        end
      end

      # No transition matched
      nil
    end
def transition_for(object, requirements = {})
      requirements.assert_valid_keys(:from, :to, :guard)
      requirements[:from] = machine.states.match!(object).name unless custom_from_state = requirements.include?(:from)

      branches.each do |branch|
        if match = branch.match(object, requirements)
          # Branch allows for the transition to occur
          from = requirements[:from]
          to = if match[:to].is_a?(LoopbackMatcher)
                 from
               else
                 values = requirements.include?(:to) ? [requirements[:to]].flatten : [from] | machine.states.map { |state| state.name }

                 match[:to].filter(values).first
               end

          return Transition.new(object, machine, name, from, to, !custom_from_state)
        end
      end

      # No transition matched
      nil
    end
Finds and builds the next transition that can be performed on the given
 object.  If no transitions can be made, then this will return nil.

 Valid requirement options:
 * <tt>:from</tt> - One or more states being transitioned from.  If none
   are specified, then this will be the object's current state.
 * <tt>:to</tt> - One or more states being transitioned to.  If none are
   specified, then this will match any to state.
 * <tt>:guard</tt> - Whether to guard transitions with the if/unless
   conditionals defined for each one.  Default is true.