Class: Reel::Spy
Overview
Prints out all traffic to a Reel server. Useful for debugging
Defined Under Namespace
Modules: Colors
Instance Method Summary collapse
-
#close ⇒ Object
Close the socket.
-
#connected ⇒ Object
Log a connection to this server.
-
#initialize(socket, logger = STDOUT) ⇒ Spy
constructor
A new instance of Spy.
-
#log(type, str) ⇒ Object
Log the given event.
-
#readpartial(maxlen, outbuf = "") ⇒ Object
Read from the client.
-
#write(string) ⇒ Object
(also: #<<)
Write data to the client.
Constructor Details
#initialize(socket, logger = STDOUT) ⇒ Spy
Returns a new instance of Spy.
11 12 13 14 15 |
# File 'lib/reel/spy.rb', line 11 def initialize(socket, logger = STDOUT) @socket, @logger = socket, logger @proto, @port, _, @ip = @socket.peeraddr connected end |
Instance Method Details
#close ⇒ Object
Close the socket
37 38 39 40 |
# File 'lib/reel/spy.rb', line 37 def close @socket.close log :close, "--- #{@ip}:#{@port} (#{@proto}) disconnected\n" end |
#connected ⇒ Object
Log a connection to this server
18 19 20 |
# File 'lib/reel/spy.rb', line 18 def connected log :connect, "+++ #{@ip}:#{@port} (#{@proto}) connected\n" end |
#log(type, str) ⇒ Object
Log the given event
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/reel/spy.rb', line 43 def log(type, str) case type when :connect @logger << Colors.green(str) when :close @logger << Colors.red(str) when :read @logger << Colors.gold(str) when :write @logger << Colors.white(str) else raise "unknown event type: #{type.inspect}" end end |
#readpartial(maxlen, outbuf = "") ⇒ Object
Read from the client
23 24 25 26 27 |
# File 'lib/reel/spy.rb', line 23 def readpartial(maxlen, outbuf = "") data = @socket.readpartial(maxlen, outbuf) log :read, data data end |
#write(string) ⇒ Object Also known as: <<
Write data to the client
30 31 32 33 |
# File 'lib/reel/spy.rb', line 30 def write(string) log :write, string @socket << string end |