Class: SimpleStateMachine::Transition
- Inherits:
-
Object
- Object
- SimpleStateMachine::Transition
- Defined in:
- lib/simple_state_machine/transition.rb
Overview
Defines transitions for events
Instance Attribute Summary collapse
-
#event_name ⇒ Object
readonly
Returns the value of attribute event_name.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(event_name, from, to) ⇒ Transition
constructor
A new instance of Transition.
-
#is_error_transition_for?(event_name, error) ⇒ Boolean
returns true if it’s a error transition for event_name and error.
-
#is_transition_for?(event_name, subject_state) ⇒ Boolean
returns true if it’s a transition for event_name and subject_state.
-
#to_graphviz_dot ⇒ Object
TODO move to Graphiz module.
- #to_s ⇒ Object
Constructor Details
#initialize(event_name, from, to) ⇒ Transition
Returns a new instance of Transition.
5 6 7 8 9 |
# File 'lib/simple_state_machine/transition.rb', line 5 def initialize(event_name, from, to) @event_name = event_name.to_s @from = from.is_a?(Class) ? from : from.to_s @to = to.to_s end |
Instance Attribute Details
#event_name ⇒ Object (readonly)
Returns the value of attribute event_name.
4 5 6 |
# File 'lib/simple_state_machine/transition.rb', line 4 def event_name @event_name end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/simple_state_machine/transition.rb', line 4 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/simple_state_machine/transition.rb', line 4 def to @to end |
Instance Method Details
#is_error_transition_for?(event_name, error) ⇒ Boolean
returns true if it’s a error transition for event_name and error
17 18 19 |
# File 'lib/simple_state_machine/transition.rb', line 17 def is_error_transition_for?(event_name, error) is_same_event?(event_name) && from.is_a?(Class) && error.is_a?(from) end |
#is_transition_for?(event_name, subject_state) ⇒ Boolean
returns true if it’s a transition for event_name and subject_state
12 13 14 |
# File 'lib/simple_state_machine/transition.rb', line 12 def is_transition_for?(event_name, subject_state) is_same_event?(event_name) && is_same_from?(subject_state) end |
#to_graphviz_dot ⇒ Object
TODO move to Graphiz module
26 27 28 |
# File 'lib/simple_state_machine/transition.rb', line 26 def to_graphviz_dot %("#{from}"->"#{to}"[label=#{event_name}]) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/simple_state_machine/transition.rb', line 21 def to_s "#{from}.#{event_name}! => #{to}" end |