Class: EventState::State

Inherits:
Struct
  • Object
show all
Defined in:
lib/event_state/state.rb

Overview

A state in a state machine. This class is for internal use; you will not usually need to use it directly.

Note that the Procs stored here are executed in the context of an instance of a subclass of Machine, rather than in the context in which they were defined.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



39
40
41
42
43
44
45
46
# File 'lib/event_state/state.rb', line 39

def initialize(*)
  super
  self.on_enters  ||= {}
  self.on_exits   ||= {}
  self.on_sends   ||= {}
  self.on_recvs   ||= {}
  self.on_timeout ||= lambda { close_connection }
end

Instance Attribute Details

#default_on_enterProc?

called when the state is entered via a message that does not have an associated handler in on_enters

Returns:

  • (Proc, nil)

    the current value of default_on_enter



34
35
36
# File 'lib/event_state/state.rb', line 34

def default_on_enter
  @default_on_enter
end

#default_on_exitProc?

called when the state is exited via a message that does not have an associated handler in on_exits

Returns:

  • (Proc, nil)

    the current value of default_on_exit



34
35
36
# File 'lib/event_state/state.rb', line 34

def default_on_exit
  @default_on_exit
end

#nameSymbol

state name

Returns:

  • (Symbol)

    the current value of name



34
35
36
# File 'lib/event_state/state.rb', line 34

def name
  @name
end

#on_entersHash<Symbol, Proc>

map from message names to handlers

Returns:

  • (Hash<Symbol, Proc>)

    the current value of on_enters



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_enters
  @on_enters
end

#on_exitsHash<Symbol, Proc>

map from message names to handlers

Returns:

  • (Hash<Symbol, Proc>)

    the current value of on_exits



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_exits
  @on_exits
end

#on_recvsHash<Symbol, Symbol>

map from message names to successor state names

Returns:

  • (Hash<Symbol, Symbol>)

    the current value of on_recvs



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_recvs
  @on_recvs
end

#on_sendsHash<Symbol, Symbol>

map from message names to successor state names

Returns:

  • (Hash<Symbol, Symbol>)

    the current value of on_sends



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_sends
  @on_sends
end

#on_timeoutProc

called when the timeout elapses; by default, it calls close_connection

Returns:

  • (Proc)

    the current value of on_timeout



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_timeout
  @on_timeout
end

#on_unbindObject

Returns the value of attribute on_unbind

Returns:

  • (Object)

    the current value of on_unbind



34
35
36
# File 'lib/event_state/state.rb', line 34

def on_unbind
  @on_unbind
end

#timeoutNumeric?

limit on the number of seconds to spend in this state; the on_timeout block is called after this elapses

Returns:

  • (Numeric, nil)

    the current value of timeout



34
35
36
# File 'lib/event_state/state.rb', line 34

def timeout
  @timeout
end

Instance Method Details

#call_on_enter(context, message_name, message) ⇒ Object



51
52
53
54
# File 'lib/event_state/state.rb', line 51

def call_on_enter context, message_name, message
  call_state_handler context, on_enters, default_on_enter,
    message_name, message
end

#call_on_exit(context, message_name, message) ⇒ Object



59
60
61
62
# File 'lib/event_state/state.rb', line 59

def call_on_exit context, message_name, message
  call_state_handler context, on_exits, default_on_exit,
    message_name, message
end