Class: MysqlBinlog::DebuggingReader

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_binlog/reader/debugging_reader.rb

Overview

Wrap another Reader class, passing through all method calls, but optionally printing the contents of data read, and the method calls themselves. This is very useful for debugging the library itself, or if exceptions are getting thrown when reading a possibly unsupported log.

Instance Method Summary collapse

Constructor Details

#initialize(wrapped, options = {}) ⇒ DebuggingReader

Returns a new instance of DebuggingReader.



17
18
19
20
# File 'lib/mysql_binlog/reader/debugging_reader.rb', line 17

def initialize(wrapped, options={})
  @wrapped = wrapped
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Pass through all method calls to the reader class we’re delegating to. If various options are enabled, print debugging information.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mysql_binlog/reader/debugging_reader.rb', line 24

def method_missing(method, *args)
  if @options[:calls]
    puts "#{@wrapped.class}.#{method}"
  end

  return_value = @wrapped.send(method, *args)

  # Print the returned data from :read in a nice hex dump format.
  if method == :read and @options[:data]
    puts "Read #{args[0]} bytes #{caller.first.split(":")[2]}:"
    puts hexdump(return_value)
  end

  return_value
end