Class: Librevox::Listener::Base
- Inherits:
-
EventMachine::Protocols::HeaderAndContentProtocol
- Object
- EventMachine::Protocols::HeaderAndContentProtocol
- Librevox::Listener::Base
- Defined in:
- lib/librevox/listener/base.rb
Defined Under Namespace
Classes: CommandDelegate
Instance Attribute Summary collapse
-
#response ⇒ Object
(also: #event)
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#api ⇒ Object
Exposes an instance of CommandDelegate, which includes Commands.
- #command(msg, &block) ⇒ Object
- #handle_response ⇒ Object
-
#on_event(event) ⇒ Object
override.
- #post_init ⇒ Object
- #receive_request(header, content) ⇒ Object
Instance Attribute Details
#response ⇒ Object Also known as: event
Returns the value of attribute response.
50 51 52 |
# File 'lib/librevox/listener/base.rb', line 50 def response @response end |
Class Method Details
.event(event, &block) ⇒ Object
13 14 15 |
# File 'lib/librevox/listener/base.rb', line 13 def event event, &block hooks[event] << block end |
.hooks ⇒ Object
9 10 11 |
# File 'lib/librevox/listener/base.rb', line 9 def hooks @hooks ||= Hash.new {|hash, key| hash[key] = []} end |
Instance Method Details
#api ⇒ Object
Exposes an instance of CommandDelegate, which includes Commands.
40 41 42 |
# File 'lib/librevox/listener/base.rb', line 40 def api @command_delegate ||= CommandDelegate.new(self) end |
#command(msg, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/librevox/listener/base.rb', line 44 def command msg, &block send_data "#{msg}\n\n" @command_queue.push(block) end |
#handle_response ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/librevox/listener/base.rb', line 62 def handle_response if response.api_response? && @command_queue.any? @command_queue.shift.call(response) end if response.event? on_event(response.dup) invoke_event_hooks end end |
#on_event(event) ⇒ Object
override
74 75 |
# File 'lib/librevox/listener/base.rb', line 74 def on_event event end |
#post_init ⇒ Object
53 54 55 |
# File 'lib/librevox/listener/base.rb', line 53 def post_init @command_queue = [] end |