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.



102
103
104
# File 'lib/duoconsole.rb', line 102

def initialize socket
  @socket = socket
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



100
101
102
# File 'lib/duoconsole.rb', line 100

def socket
  @socket
end

Instance Method Details

#startObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/duoconsole.rb', line 106

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

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

    socket.write(retval)
  end
end