Class: Invoker::CommandListener::Client
- Inherits:
-
Object
- Object
- Invoker::CommandListener::Client
- Defined in:
- lib/invoker/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/invoker/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/invoker/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 19 20 |
# File 'lib/invoker/command_listener/client.rb', line 9 def read_and_execute command_info = client_socket.gets() command_info && command_info.strip! if command_info && !command_info.empty? worker_command, command_label, rest_args = command_info.strip.split(" ") worker_command.strip! if worker_command run_command(worker_command, command_label, rest_args) end end end |
#run_command(worker_command, command_label, rest_args = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/invoker/command_listener/client.rb', line 22 def run_command(worker_command, command_label, rest_args = nil) case worker_command when 'add' Invoker::COMMANDER.on_next_tick(command_label) { |b_command_label| add_command_by_label(b_command_label) } when 'list' json = Invoker::COMMANDER.list_commands() client_socket.puts(json) when 'remove' Invoker::COMMANDER.on_next_tick(command_label, rest_args) { |b_command_label,b_rest_args| remove_command(b_command_label, b_rest_args) } when 'reload' Invoker::COMMANDER.on_next_tick(command_label, rest_args) { |b_command_label, b_rest_args| reload_command(b_command_label, b_rest_args) } else Invoker::Logger.puts("\n Invalid command".color(:red)) end end |