Class: Stateflow::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/stateflow/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#decideObject (readonly)

Returns the value of attribute decide.



5
6
7
# File 'lib/stateflow/transition.rb', line 5

def decide
  @decide
end

#fromObject (readonly)

Returns the value of attribute from.



5
6
7
# File 'lib/stateflow/transition.rb', line 5

def from
  @from
end

#ifObject (readonly)

Returns the value of attribute if.



5
6
7
# File 'lib/stateflow/transition.rb', line 5

def if
  @if
end

#toObject (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

Returns:

  • (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