module WTF::QueryTracker

Constants

Trackable

Attributes

trackables[R]

Public Class Methods

match(pattern, sql) click to toggle source
# File lib/wtf/query_tracker.rb, line 36
def match(pattern, sql)
  case pattern
  when Regexp
    pattern.match(sql)
  when String
    pattern == sql
  when Proc
    pattern.call(sql)
  end
end
on_sql(sql) click to toggle source
# File lib/wtf/query_tracker.rb, line 28
def on_sql(sql)
  trackables.each do |it|
    if match(it.pattern, sql)
      WTF::Dumper.new(:sql, sql, *caller.take(it.options[:size] || 30), :line).call
    end
  end
end
prepare_hook() click to toggle source
# File lib/wtf/query_tracker.rb, line 16
def prepare_hook
  ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval %{
    module TrackingSQL
      def log(sql, *args, &block)
        WTF::QueryTracker.on_sql(sql)
        super(sql, *args, &block)
      end
    end
    prepend TrackingSQL
  }
end
start_tracking(pattern, options = {}) click to toggle source
# File lib/wtf/query_tracker.rb, line 8
def start_tracking(pattern, options = {})
  if @trackables.nil?
    prepare_hook
    @trackables = []
  end
  @trackables << Trackable.new(pattern, options)
end