class RorVsWild::Plugin::ActiveRecord
def self.setup
def self.setup return if @installed setup_callback @installed = true end
def self.setup_callback
def self.setup_callback return unless defined?(::ActiveSupport::Notifications.subscribe) ActiveSupport::Notifications.subscribe("sql.active_record", new) end
def finish(name, id, payload)
def finish(name, id, payload) return if IGNORED_QUERIES.include?(payload[:name]) RorVsWild::Section.stop end
def normalize_sql_query(sql)
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
def start(name, id, payload)
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