class StatefulEnum::StateInspector

Public Class Methods

new(defined_stateful_enums, model_instance) click to toggle source
# File lib/stateful_enum/state_inspection.rb, line 21
def initialize(defined_stateful_enums, model_instance)
  @defined_stateful_enums, @model_instance = defined_stateful_enums, model_instance
end

Public Instance Methods

possible_event_names() click to toggle source

List of possible event names from the current state

# File lib/stateful_enum/state_inspection.rb, line 31
def possible_event_names
  possible_events.map(&:value_method_name)
end
possible_events() click to toggle source

List of possible events from the current state

# File lib/stateful_enum/state_inspection.rb, line 26
def possible_events
  @defined_stateful_enums.flat_map {|se| se.events.select {|e| @model_instance.send("can_#{e.value_method_name}?") } }
end
possible_states() click to toggle source

List of transitionable states from the current state

# File lib/stateful_enum/state_inspection.rb, line 36
def possible_states
  @defined_stateful_enums.flat_map do |stateful_enum|
    col = stateful_enum.instance_variable_get :@column
    pe = stateful_enum.events.select {|e| @model_instance.send("can_#{e.value_method_name}?") }
    pe.flat_map {|e| e.instance_variable_get(:@transitions)[@model_instance.send(col).to_sym].first }
  end
end