Class: Duoconsole::CommandClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ CommandClient

Returns a new instance of CommandClient.



118
119
120
# File 'lib/duoconsole.rb', line 118

def initialize socket
  @socket = socket
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



137
138
139
# File 'lib/duoconsole.rb', line 137

def method_missing(m, *args, &block)
  send "#{m} #{args.join(' ')}"
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



116
117
118
# File 'lib/duoconsole.rb', line 116

def socket
  @socket
end

Instance Method Details

#recvObject



127
128
129
130
131
132
133
134
135
# File 'lib/duoconsole.rb', line 127

def recv
  socket.recv(1000)
rescue IRB::Abort => e
  # IRB::Abort is triggered by ctrl-c
  # When raise, we didn't get to recv message returned from this run
  # Clear it out now so that it won't be in the buffer for next run
  socket.recv(1000)
  raise e
end

#send(msg) ⇒ Object



122
123
124
125
# File 'lib/duoconsole.rb', line 122

def send msg
  socket.write(msg)
  recv
end