Sha256: 608c8acc993c985412149e94e5e6a306dc90eee39abd7d3c8eead58bf13a9d0e

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

module StateMachine
  # Provides a set of helper methods for generating matchers
  module MatcherHelpers
    # 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+
    def all
      AllMatcher.instance
    end
    alias_method :any, :all
    
    # 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 :parked => :parked, :first_gear => :first_gear
    def same
      LoopbackMatcher.instance
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
state_machine-0.6.0 lib/state_machine/matcher_helpers.rb
state_machine-0.6.3 lib/state_machine/matcher_helpers.rb
state_machine-0.6.1 lib/state_machine/matcher_helpers.rb
state_machine-0.6.2 lib/state_machine/matcher_helpers.rb
state_machine-0.7.0 lib/state_machine/matcher_helpers.rb
state_machine-0.7.4 lib/state_machine/matcher_helpers.rb
state_machine-0.7.2 lib/state_machine/matcher_helpers.rb
state_machine-0.7.1 lib/state_machine/matcher_helpers.rb
state_machine-0.7.5 lib/state_machine/matcher_helpers.rb
state_machine-0.7.3 lib/state_machine/matcher_helpers.rb