Class: Philiprehberger::StateMachine::Transition

Inherits:
Struct
  • Object
show all
Defined in:
lib/philiprehberger/state_machine/transition.rb

Overview

Represents a single transition from one or more states to a target state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fromSymbol+ (readonly)

source state(s)

Returns:

  • (Symbol, Array<Symbol>)

    the current value of from



10
11
12
# File 'lib/philiprehberger/state_machine/transition.rb', line 10

def from
  @from
end

#guardProc? (readonly)

optional guard condition

Returns:

  • (Proc, nil)

    the current value of guard



10
11
12
# File 'lib/philiprehberger/state_machine/transition.rb', line 10

def guard
  @guard
end

#toSymbol (readonly)

target state

Returns:

  • (Symbol)

    the current value of to



10
11
12
# File 'lib/philiprehberger/state_machine/transition.rb', line 10

def to
  @to
end

Instance Method Details

#from_statesArray<Symbol>

Returns all source states as an array.

Returns:

  • (Array<Symbol>)


26
27
28
# File 'lib/philiprehberger/state_machine/transition.rb', line 26

def from_states
  Array(from)
end

#matches?(current_state) ⇒ Boolean

Check if this transition matches the given current state.

Parameters:

  • current_state (Symbol)

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/philiprehberger/state_machine/transition.rb', line 15

def matches?(current_state)
  if from.is_a?(Array)
    from.include?(current_state)
  else
    from == current_state
  end
end