Class: Hahamut::Manager
- Inherits:
-
Object
- Object
- Hahamut::Manager
- Includes:
- Singleton
- Defined in:
- lib/hahamut/manager.rb
Overview
Client Manager
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
Class Method Summary collapse
Instance Method Summary collapse
- #get(id) ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #on_message(&block) ⇒ Object
- #register(args) ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
26 27 28 |
# File 'lib/hahamut/manager.rb', line 26 def initialize @clients = {} end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
24 25 26 |
# File 'lib/hahamut/manager.rb', line 24 def handler @handler end |
Class Method Details
.find(id) ⇒ Object
15 16 17 |
# File 'lib/hahamut/manager.rb', line 15 def find(id) instance.get(id) end |
.handle(client, message) ⇒ Object
19 20 21 |
# File 'lib/hahamut/manager.rb', line 19 def handle(client, ) instance.handler&.call(client, ) end |
.register(client) ⇒ Object
11 12 13 |
# File 'lib/hahamut/manager.rb', line 11 def register(client) instance.register(client) end |
Instance Method Details
#get(id) ⇒ Object
39 40 41 |
# File 'lib/hahamut/manager.rb', line 39 def get(id) @clients[id] end |
#on_message(&block) ⇒ Object
43 44 45 |
# File 'lib/hahamut/manager.rb', line 43 def (&block) @handler = block end |
#register(args) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/hahamut/manager.rb', line 30 def register(args) case args when Hash then client = create_from(args) when Client then client = args end @clients[client.id] = client end |