class Stateful::StateInfo

Attributes

children[R]
name[R]
parent[R]
to_transitions[R]

Public Class Methods

new(state_class, attr_name, parent, name, config) click to toggle source
# File lib/stateful/state_info.rb, line 4
def initialize(state_class, attr_name, parent, name, config)
  @attr_name = attr_name
  @state_class = state_class
  if parent
    @parent = parent
    parent.children << self
  end

  @name = name
  @to_transitions = []

  if config.is_a?(Hash)
    @groupConfig = config
    @children = []
  else
    @to_transitions = config ? (config.is_a?(Array) ? config : [config]) : []
  end
end

Public Instance Methods

can_transition_to?(state) click to toggle source
# File lib/stateful/state_info.rb, line 35
def can_transition_to?(state)
  state_info = infos[state]
  if is_group? or state_info.nil? or state_info.is_group?
    false
  else
    to_transitions.include?(state)
  end
end
collect_child_states() click to toggle source
# File lib/stateful/state_info.rb, line 44
def collect_child_states
  is_group? ? children.flat_map(&:collect_child_states) : [name]
end
expand_to_transitions() click to toggle source
# File lib/stateful/state_info.rb, line 48
def expand_to_transitions
  if to_transitions.any?
    @to_transitions = to_transitions.flat_map do |to|
      info = infos[to]

      if info.is_group?
        info.collect_child_states
      else
        [info.name]
      end
    end
  end
end
infos() click to toggle source
# File lib/stateful/state_info.rb, line 31
def infos
  @state_class.__send__("#{@attr_name}_infos")
end
is?(state) click to toggle source
# File lib/stateful/state_info.rb, line 23
def is?(state)
  !!(@name == state or (parent and parent.is?(state)))
end
is_group?() click to toggle source
# File lib/stateful/state_info.rb, line 27
def is_group?
  !!@groupConfig
end