Module: Apollo::InstanceMethods

Defined in:
lib/apollo.rb

Instance Method Summary collapse

Instance Method Details

#current_stateObject



60
61
62
63
64
# File 'lib/apollo.rb', line 60

def current_state
  loaded_state = load_apollo_state
  res = spec.states[loaded_state.to_sym] if loaded_state
  res || spec.initial_state
end

#halted?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/apollo.rb', line 66

def halted?
  @halted
end

#halted_becauseObject



70
71
72
# File 'lib/apollo.rb', line 70

def halted_because
  @halted_because
end

#process_event!(name, *args) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/apollo.rb', line 74

def process_event!(name, *args)
  event = current_state.events[name.to_sym]
  raise NoTransitionAllowed.new(
    "There is no event #{name.to_sym} defined for the #{current_state} state") \
    if event.nil?
  # This three member variables are a relict from the old apollo library
  # TODO: refactor some day
  @halted_because = nil
  @halted = false
  @raise_exception_on_halt = false
  return_value = run_action(event.action, *args) || run_action_callback(event.name, *args)
  if @halted
    if @raise_exception_on_halt
      raise @raise_exception_on_halt
    else
      false
    end
  else
    check_transition(event)
    run_on_transition(current_state, spec.states[event.to], name, *args)
    transition(current_state, spec.states[event.to], name, *args)
    return_value
  end
end