class Necro::CommandListener::Client

Attributes

client_socket[RW]

Public Class Methods

new(client_socket) click to toggle source
# File lib/necro/command_listener/client.rb, line 5
def initialize(client_socket)
  @client_socket = client_socket
end

Public Instance Methods

read_and_execute() click to toggle source
# File lib/necro/command_listener/client.rb, line 9
def read_and_execute
  command_info = client_socket.read()
  if command_info && !command_info.empty?
    worker_command, command_label, rest_args = command_info.strip.split(" ")
    if worker_command && command_label
      run_command(worker_command, command_label, rest_args)
    end
  end
  client_socket.close()
end
run_command(worker_command, command_label, rest_args = nil) click to toggle source
# File lib/necro/command_listener/client.rb, line 20
def run_command(worker_command, command_label, rest_args = nil)
  case worker_command
  when 'add'
    Necro::COMMANDER.add_command_by_label(command_label)
  when 'remove'
    Necro::COMMANDER.remove_command(command_label, rest_args)
  when 'reload'
    Necro::COMMANDER.reload_command(command_label)
  else
    $stdout.puts("\n Invalid command".red)
  end
end