Exception: StateMachines::InvalidTransition

Inherits:
Error
  • Object
show all
Defined in:
lib/state_machines/error.rb

Overview

An invalid transition was attempted

Instance Attribute Summary collapse

Attributes inherited from Error

#object

Instance Method Summary collapse

Constructor Details

#initialize(object, machine, event) ⇒ InvalidTransition

:nodoc:



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/state_machines/error.rb', line 64

def initialize(object, machine, event) #:nodoc:
  @machine = machine
  @from_state = machine.states.match!(object)
  @from = machine.read(object, :state)
  @event = machine.events.fetch(event)
  errors = machine.errors_for(object)

  message = "Cannot transition #{machine.name} via :#{self.event} from #{from_name.inspect}"
  message << " (Reason(s): #{errors})" unless errors.empty?
  super(object, message)
end

Instance Attribute Details

#fromObject (readonly)

The current state value for the machine



62
63
64
# File 'lib/state_machines/error.rb', line 62

def from
  @from
end

#machineObject (readonly)

The machine attempting to be transitioned



59
60
61
# File 'lib/state_machines/error.rb', line 59

def machine
  @machine
end

Instance Method Details

#eventObject

The event that triggered the failed transition



77
78
79
# File 'lib/state_machines/error.rb', line 77

def event
  @event.name
end

#from_nameObject

The name for the current state



87
88
89
# File 'lib/state_machines/error.rb', line 87

def from_name
  @from_state.name
end

#qualified_eventObject

The fully-qualified name of the event that triggered the failed transition



82
83
84
# File 'lib/state_machines/error.rb', line 82

def qualified_event
  @event.qualified_name
end

#qualified_from_nameObject

The fully-qualified name for the current state



92
93
94
# File 'lib/state_machines/error.rb', line 92

def qualified_from_name
  @from_state.qualified_name
end