class Explorer::IPCClient

Public Class Methods

new(socket_path = '/tmp/explorer_ipc') click to toggle source
# File lib/explorer/ipc_client.rb, line 9
def initialize(socket_path = '/tmp/explorer_ipc')
  @socket_path = socket_path
  @socket = UNIXSocket.open(socket_path)
end

Public Instance Methods

cmd_add(label, cmd, dir=nil) click to toggle source
# File lib/explorer/ipc_client.rb, line 53
def cmd_add(label, cmd, dir=nil)
  msg = {
    command: 'cmd-add',
    label: label,
    cmd: cmd,
    dir: dir,
  }
  @socket.puts msg.to_json
end
cmd_list() click to toggle source
# File lib/explorer/ipc_client.rb, line 87
def cmd_list
  msg = {
    command: 'cmd-list'
  }
  @socket.puts msg.to_json
  JSON.parse @socket.readline
end
cmd_remove(label) click to toggle source
# File lib/explorer/ipc_client.rb, line 79
def cmd_remove(label)
  msg = {
    command: 'cmd-remove',
    label: label,
  }
  @socket.puts msg.to_json
end
cmd_start(label) click to toggle source
# File lib/explorer/ipc_client.rb, line 63
def cmd_start(label)
  msg = {
    command: 'cmd-start',
    label: label,
  }
  @socket.puts msg.to_json
end
cmd_stop(label) click to toggle source
# File lib/explorer/ipc_client.rb, line 71
def cmd_stop(label)
  msg = {
    command: 'cmd-stop',
    label: label,
  }
  @socket.puts msg.to_json
end
hostmap_add(map, host, port) click to toggle source
# File lib/explorer/ipc_client.rb, line 22
def hostmap_add map, host, port
  msg = {
    command: 'map-add',
    map: map,
    host: host,
    port: port
  }
  @socket.puts msg.to_json
end
hostmap_list() click to toggle source
# File lib/explorer/ipc_client.rb, line 14
def hostmap_list
  msg = {
    command: 'map-list'
  }
  @socket.puts msg.to_json
  JSON.parse @socket.readline
end
hostmap_remove(domain) click to toggle source
# File lib/explorer/ipc_client.rb, line 32
def hostmap_remove domain
  msg = {
    command: 'map-remove',
    map: domain
  }
  @socket.puts msg.to_json
end
shutdown() click to toggle source
# File lib/explorer/ipc_client.rb, line 95
def shutdown
  @socket.close if @socket
end
tail(io = STDOUT) click to toggle source
# File lib/explorer/ipc_client.rb, line 40
def tail(io = STDOUT)
  msg = {
    command: 'cmd-tail'
  }
  @socket.puts msg.to_json

  loop do
    line = @socket.gets
    io.puts line
  end
rescue IOError
end