Class: Necro::CommandListener::Client
- Inherits:
-
Object
- Object
- Necro::CommandListener::Client
- Defined in:
- lib/necro/command_listener/client.rb
Instance Attribute Summary collapse
-
#client_socket ⇒ Object
Returns the value of attribute client_socket.
Instance Method Summary collapse
-
#initialize(client_socket) ⇒ Client
constructor
A new instance of Client.
- #read_and_execute ⇒ Object
- #run_command(worker_command, command_label, rest_args = nil) ⇒ Object
Constructor Details
#initialize(client_socket) ⇒ Client
Returns a new instance of Client.
5 6 7 |
# File 'lib/necro/command_listener/client.rb', line 5 def initialize(client_socket) @client_socket = client_socket end |
Instance Attribute Details
#client_socket ⇒ Object
Returns the value of attribute client_socket.
4 5 6 |
# File 'lib/necro/command_listener/client.rb', line 4 def client_socket @client_socket end |
Instance Method Details
#read_and_execute ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 |