Class: Pazuzu::Control::SocketClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pazuzu/control/socket_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SocketClient

Returns a new instance of SocketClient.



6
7
8
9
# File 'lib/pazuzu/control/socket_client.rb', line 6

def initialize(path)
  @path = path
  @socket = UNIXSocket.new(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



24
25
26
# File 'lib/pazuzu/control/socket_client.rb', line 24

def path
  @path
end

Instance Method Details

#execute(command, *arguments) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pazuzu/control/socket_client.rb', line 11

def execute(command, *arguments)
  command_line = [command, *arguments].join(' ')
  command_line << "\n"
  
  @socket.write(command_line)
  
  num_bytes = @socket.read(10).to_i(16)
  if num_bytes > 0
    data = @socket.read(num_bytes)
    return JSON.parse(data)
  end
end