Class: EventState::State
- Inherits:
-
Struct
- Object
- Struct
- EventState::State
- 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 Proc
s 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
-
#default_on_enter ⇒ Proc?
called when the state is entered via a message that does not have an associated handler in
on_enters
. -
#default_on_exit ⇒ Proc?
called when the state is exited via a message that does not have an associated handler in
on_exits
. -
#name ⇒ Symbol
state name.
-
#on_enters ⇒ Hash<Symbol, Proc>
map from message names to handlers.
-
#on_exits ⇒ Hash<Symbol, Proc>
map from message names to handlers.
-
#on_recvs ⇒ Hash<Symbol, Symbol>
map from message names to successor state names.
-
#on_sends ⇒ Hash<Symbol, Symbol>
map from message names to successor state names.
-
#on_timeout ⇒ Proc
called when the timeout elapses; by default, it calls
close_connection
. -
#on_unbind ⇒ Object
Returns the value of attribute on_unbind.
-
#timeout ⇒ Numeric?
limit on the number of seconds to spend in this state; the
on_timeout
block is called after this elapses.
Instance Method Summary collapse
- #call_on_enter(context, message_name, message) ⇒ Object
- #call_on_exit(context, message_name, message) ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize ⇒ State
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_enter ⇒ Proc?
called when the state is entered via a message that does not have an associated handler in on_enters
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def default_on_enter @default_on_enter end |
#default_on_exit ⇒ Proc?
called when the state is exited via a message that does not have an associated handler in on_exits
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def default_on_exit @default_on_exit end |
#name ⇒ Symbol
state name
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def name @name end |
#on_enters ⇒ Hash<Symbol, Proc>
map from message names to handlers
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_enters @on_enters end |
#on_exits ⇒ Hash<Symbol, Proc>
map from message names to handlers
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_exits @on_exits end |
#on_recvs ⇒ Hash<Symbol, Symbol>
map from message names to successor state names
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_recvs @on_recvs end |
#on_sends ⇒ Hash<Symbol, Symbol>
map from message names to successor state names
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_sends @on_sends end |
#on_timeout ⇒ Proc
called when the timeout elapses; by default, it calls close_connection
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_timeout @on_timeout end |
#on_unbind ⇒ Object
Returns the value of attribute on_unbind
34 35 36 |
# File 'lib/event_state/state.rb', line 34 def on_unbind @on_unbind end |
#timeout ⇒ Numeric?
limit on the number of seconds to spend in this state; the on_timeout
block is called after this elapses
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, , call_state_handler context, on_enters, default_on_enter, , 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, , call_state_handler context, on_exits, default_on_exit, , end |