class RorVsWild::Plugin::ActiveRecord

Constants

IGNORED_QUERIES
SQL_IN_REGEX
SQL_MULTI_LINE_COMMENT_REGEX
SQL_NUMERIC_REGEX
SQL_ONE_LINE_COMMENT_REGEX
SQL_PARAMETER_REGEX
SQL_STRING_REGEX

Public Class Methods

setup() click to toggle source
# File lib/rorvswild/plugin/active_record.rb, line 6
def self.setup
  return if @installed
  setup_callback
  @installed = true
end
setup_callback() click to toggle source
# File lib/rorvswild/plugin/active_record.rb, line 12
def self.setup_callback
  return unless defined?(::ActiveSupport::Notifications.subscribe)
  ActiveSupport::Notifications.subscribe("sql.active_record", new)
end

Public Instance Methods

finish(name, id, payload) click to toggle source
# File lib/rorvswild/plugin/active_record.rb, line 27
def finish(name, id, payload)
  return if IGNORED_QUERIES.include?(payload[:name])
  RorVsWild::Section.stop
end
normalize_sql_query(sql) click to toggle source
# File lib/rorvswild/plugin/active_record.rb, line 39
def normalize_sql_query(sql)
  sql = sql.to_s.gsub(SQL_STRING_REGEX, "?")
  sql.gsub!(SQL_PARAMETER_REGEX, "?")
  sql.gsub!(SQL_NUMERIC_REGEX, "?")
  sql.gsub!(SQL_IN_REGEX, '\1?\3')
  sql.gsub!(SQL_ONE_LINE_COMMENT_REGEX, "")
  sql.gsub!(SQL_MULTI_LINE_COMMENT_REGEX, "")
  sql.strip!
  sql
end
start(name, id, payload) click to toggle source
# File lib/rorvswild/plugin/active_record.rb, line 19
def start(name, id, payload)
  return if IGNORED_QUERIES.include?(payload[:name])
  RorVsWild::Section.start do |section|
    section.commands << normalize_sql_query(payload[:sql])
    section.kind = "sql"
  end
end