Class: Stateflow::Transition
- Inherits:
-
Object
- Object
- Stateflow::Transition
- Defined in:
- lib/stateflow/transition.rb
Instance Attribute Summary collapse
-
#decide ⇒ Object
readonly
Returns the value of attribute decide.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#if ⇒ Object
readonly
Returns the value of attribute if.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #can_transition?(base) ⇒ Boolean
- #find_to_state(base) ⇒ Object
-
#initialize(args) ⇒ Transition
constructor
A new instance of Transition.
Constructor Details
#initialize(args) ⇒ Transition
Returns a new instance of Transition.
7 8 9 10 11 12 |
# File 'lib/stateflow/transition.rb', line 7 def initialize(args) @from = [args[:from]].flatten @to = args[:to] @if = args[:if] @decide = args[:decide] end |
Instance Attribute Details
#decide ⇒ Object (readonly)
Returns the value of attribute decide.
5 6 7 |
# File 'lib/stateflow/transition.rb', line 5 def decide @decide end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
5 6 7 |
# File 'lib/stateflow/transition.rb', line 5 def from @from end |
#if ⇒ Object (readonly)
Returns the value of attribute if.
5 6 7 |
# File 'lib/stateflow/transition.rb', line 5 def if @if end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
5 6 7 |
# File 'lib/stateflow/transition.rb', line 5 def to @to end |
Instance Method Details
#can_transition?(base) ⇒ Boolean
14 15 16 17 |
# File 'lib/stateflow/transition.rb', line 14 def can_transition?(base) return true unless @if execute_action(@if, base) end |
#find_to_state(base) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/stateflow/transition.rb', line 19 def find_to_state(base) raise IncorrectTransition.new("Array of destinations and no decision") if @to.is_a?(Array) && @decide.nil? return @to unless @to.is_a?(Array) to = execute_action(@decide, base) raise NoStateFound.new("Decision did not return a state that was set in the 'to' argument") unless @to.include?(to) to end |