Class: Hahamut::Manager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hahamut/manager.rb

Overview

Client Manager

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



26
27
28
# File 'lib/hahamut/manager.rb', line 26

def initialize
  @clients = {}
end

Instance Attribute Details

#handlerObject

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, message)
  instance.handler&.call(client, message)
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 on_message(&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