### Home Classes Methods

### In Files

- lib/state_machine/path.rb

### Parent

Array

### Methods

- ::new
- #complete?
- #events
- #from_name
- #from_states
- #to_name
- #to_states
- #walk

### Included Modules

- StateMachine::Assertions

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StateMachine
- StateMachine::AllMatcher
- StateMachine::Assertions
- StateMachine::AttributeTransitionCollection
- StateMachine::BlacklistMatcher
- StateMachine::Branch
- StateMachine::Callback
- StateMachine::ClassMethods
- StateMachine::Error
- StateMachine::EvalHelpers
- StateMachine::Event
- StateMachine::EventCollection
- StateMachine::Graph
- StateMachine::InstanceMethods
- StateMachine::IntegrationNotFound
- StateMachine::Integrations
- StateMachine::Integrations::ActiveModel
- StateMachine::Integrations::ActiveModel::Observer
- StateMachine::Integrations::ActiveModel::ObserverUpdate
- StateMachine::Integrations::ActiveRecord
- StateMachine::Integrations::Base
- StateMachine::Integrations::Base::ClassMethods
- StateMachine::Integrations::DataMapper
- StateMachine::Integrations::DataMapper::Observer
- StateMachine::Integrations::MongoMapper
- StateMachine::Integrations::Mongoid
- StateMachine::Integrations::Sequel
- StateMachine::InvalidEvent
- StateMachine::InvalidParallelTransition
- StateMachine::InvalidTransition
- StateMachine::LoopbackMatcher
- StateMachine::Machine
- StateMachine::MachineCollection
- StateMachine::MacroMethods
- StateMachine::Matcher
- StateMachine::MatcherHelpers
- StateMachine::NodeCollection
- StateMachine::Path
- StateMachine::PathCollection
- StateMachine::RailsEngine
- StateMachine::State
- StateMachine::StateCollection
- StateMachine::StateContext
- StateMachine::Transition
- StateMachine::TransitionCollection
- StateMachine::WhitelistMatcher
- StateMachine::YARD
- StateMachine::YARD::Handlers
- StateMachine::YARD::Handlers::Base
- StateMachine::YARD::Handlers::Event
- StateMachine::YARD::Handlers::Machine
- StateMachine::YARD::Handlers::State
- StateMachine::YARD::Handlers::Transition
- Object

No matching classes.

# StateMachine::Path

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.

### Attributes

machine[R]

The state machine this path is walking

object[R]

The object whose state machine is being walked

### Public Class Methods

new(object, machine, options = {}) click to toggle source

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

    # File lib/state_machine/path.rb, line 22
    def initialize(object, machine, options = {})
      assert_valid_keys(options, :target, :guard)

      @object = object
      @machine = machine
      @target = options[:target]
      @guard = options[:guard]
    end

### Public Instance Methods

complete?() click to toggle source

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

    # File lib/state_machine/path.rb, line 85
    def complete?
      !empty? && (@target ? to_name == @target : transitions.empty?)
    end

events() click to toggle source

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

For example,

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

    # File lib/state_machine/path.rb, line 70
    def events
      map {|transition| transition.event}.uniq
    end

from_name() click to toggle source

The initial state name for this path

    # File lib/state_machine/path.rb, line 37
    def from_name
      first && first.from_name
    end

from_states() click to toggle source

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

For example,

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

    # File lib/state_machine/path.rb, line 46
    def from_states
      map {|transition| transition.from_name}.uniq
    end

to_name() click to toggle source

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.

    # File lib/state_machine/path.rb, line 52
    def to_name
      last && last.to_name
    end

to_states() click to toggle source

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

For example,

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

    # File lib/state_machine/path.rb, line 61
    def to_states
      map {|transition| transition.to_name}.uniq
    end

walk() click to toggle source

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

    # File lib/state_machine/path.rb, line 76
    def walk
      transitions.each {|transition| yield dup.push(transition)}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.