class Listen::FSM::State

Attributes

name[R]
transitions[R]

Public Class Methods

new(name, transitions, &block) click to toggle source
# File lib/listen/fsm.rb, line 115
def initialize(name, transitions, &block)
  @name = name
  @block = block
  @transitions = if transitions
    Array(transitions).map(&:to_sym)
  end
end

Public Instance Methods

call(obj) click to toggle source
# File lib/listen/fsm.rb, line 123
def call(obj)
  obj.instance_eval(&@block) if @block
end
valid_transition?(new_state) click to toggle source
# File lib/listen/fsm.rb, line 127
def valid_transition?(new_state)
  # All transitions are allowed if none are expressly declared
  !@transitions || @transitions.include?(new_state.to_sym)
end