Class StateMachine::Path
In: lib/state_machine/path.rb
Parent: Array

A path represents a sequence of transitions that can be run for a particular object. Paths can walk to new transitions, revealing all of the possible branches that can be encountered in the object‘s state machine.

Methods

complete?   events   from_name   from_states   new   to_name   to_states   walk  

Included Modules

Assertions

Attributes

machine  [R]  The state machine this path is walking
object  [R]  The object whose state machine is being walked

Public Class methods

Creates a new transition path for the given object. Initially this is an empty path. In order to start walking the path, it must be populated with an initial transition.

Configuration options:

  • :target - The target state to end the path on
  • :guard - Whether to guard transitions with the if/unless conditionals defined for each one

Public Instance methods

Determines whether or not this path has completed. A path is considered complete when one of the following conditions is met:

  • The last transition in the path ends on the target state
  • There are no more transitions remaining to walk and there is no target state

Lists all of the events that can be fired through this path.

For example,

  path.events # => [:park, :ignite, :shift_up, ...]

The initial state name for this path

Lists all of the from states that can be reached through this path.

For example,

  path.to_states  # => [:parked, :idling, :first_gear, ...]

The end state name for this path. If a target state was specified for the path, then that will be returned if the path is complete.

Lists all of the to states that can be reached through this path.

For example,

  path.to_states  # => [:parked, :idling, :first_gear, ...]

Walks down the next transitions at the end of this path. This will only walk down paths that are considered valid.

[Validate]