Class | StateMachine::Path |
In: |
lib/state_machine/path.rb
|
Parent: | Array |
machine | [R] | The state machine this path is walking |
object | [R] | The object whose state machine is being walked |
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:
# File lib/state_machine/path.rb, line 22 22: def initialize(object, machine, options = {}) 23: assert_valid_keys(options, :target, :guard) 24: 25: @object = object 26: @machine = machine 27: @target = options[:target] 28: @guard = options[:guard] 29: end
Determines whether or not this path has completed. A path is considered complete when one of the following conditions is met:
# File lib/state_machine/path.rb, line 85 85: def complete? 86: !empty? && (@target ? to_name == @target : transitions.empty?) 87: end
The initial state name for this path
# File lib/state_machine/path.rb, line 37 37: def from_name 38: first && first.from_name 39: end
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 46: def from_states 47: map {|transition| transition.from_name}.uniq 48: end
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 52: def to_name 53: last && last.to_name 54: end
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 61: def to_states 62: map {|transition| transition.to_name}.uniq 63: end