Class: Rubyfox::Client::ExtensionHandler
- Inherits:
-
Object
- Object
- Rubyfox::Client::ExtensionHandler
- Defined in:
- lib/rubyfox/client/extension_handler.rb
Defined Under Namespace
Classes: Request
Instance Method Summary collapse
- #add(*names, &block) ⇒ Object
- #dispatch(request) ⇒ Object
-
#initialize(event_handler) ⇒ ExtensionHandler
constructor
A new instance of ExtensionHandler.
- #register ⇒ Object
- #remove(*names) ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(event_handler) ⇒ ExtensionHandler
Returns a new instance of ExtensionHandler.
6 7 8 9 |
# File 'lib/rubyfox/client/extension_handler.rb', line 6 def initialize(event_handler) @handler = Hash.new { |hash, type| hash[type] = [] } @event_handler = event_handler end |
Instance Method Details
#add(*names, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/rubyfox/client/extension_handler.rb', line 22 def add(*names, &block) names.each do |name| @handler[name.to_s] << block end end |
#dispatch(request) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rubyfox/client/extension_handler.rb', line 34 def dispatch(request) command = request.command @handler[command].each do |handler| handler.call(request) end end |
#register ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rubyfox/client/extension_handler.rb', line 11 def register @event_handler.add(:extension_response) do |event| request = Request.new(*event.arguments.values_at("cmd", "params", "sourceRoom", "packetId")) dispatch(request) end end |
#remove(*names) ⇒ Object
28 29 30 31 32 |
# File 'lib/rubyfox/client/extension_handler.rb', line 28 def remove(*names) names.each do |name| @handler[name.to_s].clear end end |
#unregister ⇒ Object
18 19 20 |
# File 'lib/rubyfox/client/extension_handler.rb', line 18 def unregister @event_handler.remove(:extension_response) end |