module PedantMysql2

Constants

VERSION

Public Class Methods

capture_warnings() { || ... } click to toggle source
# File lib/pedant_mysql2.rb, line 5
def capture_warnings
  warnings = backup_warnings
  setup_capture
  yield
  captured_warnings
ensure
  restore_warnings(warnings)
end
ignore(*matchers) click to toggle source
# File lib/pedant_mysql2.rb, line 22
def ignore(*matchers)
  self.whitelist.concat(matchers.flatten)
end
on_warning() click to toggle source
# File lib/pedant_mysql2.rb, line 36
def on_warning
  Thread.current[:__pedant_mysql2_on_warning] || @_on_warning
end
on_warning=(new_proc) click to toggle source
# File lib/pedant_mysql2.rb, line 40
def on_warning=(new_proc)
  @_on_warning = new_proc
end
raise_warnings!() click to toggle source
# File lib/pedant_mysql2.rb, line 14
def raise_warnings!
  self.on_warning = nil
end
silence_warnings!() click to toggle source
# File lib/pedant_mysql2.rb, line 18
def silence_warnings!
  self.on_warning = lambda{ |warning| }
end
warn(warning) click to toggle source
# File lib/pedant_mysql2.rb, line 26
def warn(warning)
  return if ignored?(warning)

  if on_warning
    on_warning.call(warning)
  else
    raise warning
  end
end

Protected Class Methods

backup_warnings() click to toggle source
# File lib/pedant_mysql2.rb, line 67
def backup_warnings
  [captured_warnings, Thread.current[:__pedant_mysql2_on_warning]]
end
captured_warnings() click to toggle source
# File lib/pedant_mysql2.rb, line 63
def captured_warnings
  Thread.current[:__pedant_mysql2_warnings]
end
ignored?(warning) click to toggle source
# File lib/pedant_mysql2.rb, line 50
def ignored?(warning)
  note_warning?(warning) || whitelist.any? { |matcher| warning.message.match?(matcher) }
end
note_warning?(warning) click to toggle source
# File lib/pedant_mysql2.rb, line 54
def note_warning?(warning)
  warning.level == "Note"
end
restore_warnings(warnings) click to toggle source
# File lib/pedant_mysql2.rb, line 71
def restore_warnings(warnings)
  Thread.current[:__pedant_mysql2_warnings], self.thread_on_warning = *warnings
end
setup_capture() click to toggle source
# File lib/pedant_mysql2.rb, line 58
def setup_capture
  Thread.current[:__pedant_mysql2_warnings] = []
  self.thread_on_warning = lambda { |warning| Thread.current[:__pedant_mysql2_warnings] << warning }
end
thread_on_warning=(new_proc) click to toggle source
# File lib/pedant_mysql2.rb, line 75
def thread_on_warning=(new_proc)
  Thread.current[:__pedant_mysql2_on_warning] = new_proc
end
whitelist() click to toggle source
# File lib/pedant_mysql2.rb, line 46
def whitelist
  @whitelist ||= []
end