Class: Duoconsole::CommandServer

Inherits:
Object
  • Object
show all
Defined in:
lib/duoconsole.rb

Constant Summary collapse

RECOGNIZED_COMMANDS =
[:test, :rake]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ CommandServer

Returns a new instance of CommandServer.



146
147
148
# File 'lib/duoconsole.rb', line 146

def initialize socket
  @socket = socket
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



144
145
146
# File 'lib/duoconsole.rb', line 144

def socket
  @socket
end

Instance Method Details

#startObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/duoconsole.rb', line 150

def start
  loop do
    msg = socket.recv(1000)
    command, args = Marshal.load(msg)

    retval = if valid_command?(command)
      run_command(command, args)
    else
      "Unrecognized command. Valid commands are #{RECOGNIZED_COMMANDS.join(', ')}"
    end

    socket.write(retval)
  end
end