Class: Kraken::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/kraken/core/handlers/handler.rb

Overview

This class handle a Socket.

Direct Known Subclasses

Godot30Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Handler

Returns a new instance of Handler.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kraken/core/handlers/handler.rb', line 13

def initialize(socket)
  return if socket.nil?

  @socket = socket
  @thread = Thread.new do
    begin
      start
    rescue StandardError => e
      Kraken::Log.error e
      close
    end
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



11
12
13
# File 'lib/kraken/core/handlers/handler.rb', line 11

def connection
  @connection
end

Instance Method Details

#closeObject



27
28
29
30
31
32
33
34
# File 'lib/kraken/core/handlers/handler.rb', line 27

def close
  @connection.delete unless @connection.nil?

  Kraken::Log.info 'bye bye socket'

  @socket.close
  @thread.kill
end

#read_triggerObject



36
37
38
39
40
# File 'lib/kraken/core/handlers/handler.rb', line 36

def read_trigger
  trigger = read
  args = read_args
  [Kraken::Config.instance.triggers[trigger.downcase], args]
end