Module: StateMachines::MatcherHelpers
Overview
Provides a set of helper methods for generating matchers
Instance Method Summary collapse
- 
  
    
      #all  ⇒ Object 
    
    
      (also: #any)
    
  
  
  
  
  
  
  
  
  
    Represents a state that matches all known states in a machine. 
- 
  
    
      #same  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Represents a state that matches the original fromstate.
Instance Method Details
#all ⇒ Object Also known as: any
Represents a state that matches all known states in a machine.
Examples
class Vehicle
  state_machine do
    before_transition any => :parked, :do => lambda {...}
    before_transition all - :parked => all - :idling, :do => lambda {}
    event :park
      transition all => :parked
    end
    event :crash
      transition all - :parked => :stalled
    end
  end
end
In the above example, all will match the following states since they are known:
- 
parked
- 
stalled
- 
idling
| 30 31 32 | # File 'lib/state_machines/matcher_helpers.rb', line 30 def all AllMatcher.instance end | 
#same ⇒ Object
Represents a state that matches the original from state.  This is useful for defining transitions which are loopbacks.
Examples
class Vehicle
  state_machine do
    event :ignite
      transition [:idling, :first_gear] => same
    end
  end
end
In the above example, same will match whichever the from state is.  In the case of the ignite event, it is essential the same as the following:
transition :idling => :idling, :first_gear => :first_gear
| 52 53 54 | # File 'lib/state_machines/matcher_helpers.rb', line 52 def same LoopbackMatcher.instance end |