class Lignite::Connection::Tap

An adapter that delegates to another connection and records the communication

Public Class Methods

new(conn, filename) click to toggle source
# File lib/lignite/connection/tap.rb, line 10
def initialize(conn, filename)
  raise "File #{filename} exists, will not overwrite" if File.exist?(filename)
  @conn = conn
  @filename = filename
  @packets = []
end

Public Instance Methods

close() click to toggle source
Calls superclass method Lignite::Connection#close
# File lib/lignite/connection/tap.rb, line 31
def close
  y = YAML.dump(@packets)
  File.write(@filename, y)
  super
  @conn.close
end
receive() click to toggle source

@return [ByteString] a complete message

# File lib/lignite/connection/tap.rb, line 25
def receive
  s = @conn.receive
  @packets << { "RECV" => bin_to_hex(s) }
  s
end
send(payload) click to toggle source

@param payload [ByteString]

# File lib/lignite/connection/tap.rb, line 18
def send(payload)
  r = @conn.send(payload)
  @packets << { "SEND" => bin_to_hex(payload) }
  r
end