module SQLOrigin
Container module for all SQL:Origin methods.
Constants
- LIBRARY_PATHS
Paths or path prefixes that are filtered from the backtrace.
Public Class Methods
append_to_log()
click to toggle source
Enables SQL:Origin backtrace logging to the Rails log.
# File lib/sql_origin.rb, line 23 def self.append_to_log %w( PostgreSQLAdapter MysqlAdapter Mysql2Adapter OracleAdapter SQLiteAdapter SQLite3Adapter ).each do |name| adapter = ActiveRecord::ConnectionAdapters.const_get(name.to_sym) rescue nil if adapter adapter.send :include, SQLOrigin::LogHook end end ActiveRecord::LogSubscriber.send :include, SQLOrigin::LogSubscriber end
append_to_query()
click to toggle source
Enables SQL:Origin backtrace logging to SQL query comments.
# File lib/sql_origin.rb, line 35 def self.append_to_query %w( PostgreSQLAdapter MysqlAdapter Mysql2Adapter OracleAdapter SQLiteAdapter ).each do |name| adapter = ActiveRecord::ConnectionAdapters.const_get(name.to_sym) rescue nil if adapter adapter.send :include, SQLOrigin::QueryAppendHook end end end
filtered_backtrace()
click to toggle source
@return [Array<String>] The backtrace less library paths.
# File lib/sql_origin.rb, line 11 def self.filtered_backtrace caller.map do |line| line.sub /^#{Regexp.escape Rails.root.to_s}\//, '' end.select do |line| !line.starts_with?("/") && !line.starts_with?("(") && LIBRARY_PATHS.none? { |path| line.starts_with?(path) } end end