Sha256: 9e3817ecc721ba8e53809a691367a2d60b39b44e0822dfd78ee23035dbdb29cd

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

module StateMachines
  # 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+
    # * +idling+
    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

16 entries across 16 versions & 2 rubygems

Version Path
state_machines-0.5.0 lib/state_machines/matcher_helpers.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/matcher_helpers.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/matcher_helpers.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/matcher_helpers.rb
state_machines-0.4.0 lib/state_machines/matcher_helpers.rb
state_machines-0.3.0 lib/state_machines/matcher_helpers.rb
state_machines-0.2.2 lib/state_machines/matcher_helpers.rb
state_machines-0.2.1 lib/state_machines/matcher_helpers.rb
state_machines-0.2.0 lib/state_machines/matcher_helpers.rb
state_machines-0.1.4 lib/state_machines/matcher_helpers.rb
state_machines-0.1.3 lib/state_machines/matcher_helpers.rb
state_machines-0.1.2 lib/state_machines/matcher_helpers.rb
state_machines-0.1.1 lib/state_machines/matcher_helpers.rb
state_machines-0.1.0 lib/state_machines/matcher_helpers.rb
state_machines-0.0.2 lib/state_machines/matcher_helpers.rb
state_machines-0.0.1 lib/state_machines/matcher_helpers.rb