Sha256: d0763937b4ca968a28fbf47e538e98a86080da4999e008330652d178805835e6

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

module Necro
  module CommandListener
    class Client
      attr_accessor :client_socket
      def initialize(client_socket)
        @client_socket = client_socket
      end

      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
necro-0.0.2 lib/necro/command_listener/client.rb