Class: Steam::Handler::Collection
- Inherits:
-
Object
- Object
- Steam::Handler::Collection
- Includes:
- Enumerable
- Defined in:
- lib/steam/handler/collection.rb
Overview
Holds a collection of Handler objects
Instance Method Summary collapse
-
#add(*handlers) ⇒ Object
Add a handler to the collection.
-
#each(&block) ⇒ Object
Iterate through each Handler.
-
#handle(packet) ⇒ Object
Handle a packet.
-
#initialize ⇒ Collection
constructor
Creates an empty list of handlers.
Constructor Details
#initialize ⇒ Collection
Creates an empty list of handlers
13 14 15 |
# File 'lib/steam/handler/collection.rb', line 13 def initialize @handlers = [] end |
Instance Method Details
#add(*handlers) ⇒ Object
Add a handler to the collection
36 37 38 39 40 41 |
# File 'lib/steam/handler/collection.rb', line 36 def add(*handlers) handlers.each do |handler| @handlers << handler Steam.logger.debug("Added handler #{handler.class.name}") end end |
#each(&block) ⇒ Object
Iterate through each Handler. Allows the collection to act as an Enumerable
45 46 47 |
# File 'lib/steam/handler/collection.rb', line 45 def each(&block) @handlers.each(&block) end |
#handle(packet) ⇒ Object
Handle a packet. If a handler is found that cares about this packet, the packet object is passed to the handler.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/steam/handler/collection.rb', line 21 def handle(packet) handler = find_handler(packet.msg_type) if handler.nil? emsg = EMsgUtil.new(packet.emsg) Steam.logger.debug("No hander found for: #{emsg.name}") return false end handler.handle(packet) end |