Module: ActiveRecordQueryTrace
- Defined in:
- lib/active_record_query_trace.rb,
lib/active_record_query_trace/version.rb
Defined Under Namespace
Classes: CustomLogSubscriber
Constant Summary collapse
- INDENTATION =
' ' * 6
- BACKTRACE_PREFIX =
"Query Trace:\n#{INDENTATION}"
- COLORS =
{ true => '38', blue: '34', light_red: '1;31', black: '30', purple: '35', light_green: '1;32', red: '31', cyan: '36', yellow: '1;33', green: '32', gray: '37', light_blue: '1;34', brown: '33', dark_gray: '1;30', light_purple: '1;35', white: '1;37', light_cyan: '1;36' }.freeze
- VERSION =
'1.8.2'
Class Attribute Summary collapse
-
.backtrace_cleaner ⇒ Object
Returns the value of attribute backtrace_cleaner.
-
.colorize ⇒ Object
Returns the value of attribute colorize.
- .default_cleaner ⇒ Object
-
.enabled ⇒ Object
Returns the value of attribute enabled.
-
.ignore_cached_queries ⇒ Object
Returns the value of attribute ignore_cached_queries.
-
.level ⇒ Object
Returns the value of attribute level.
-
.lines ⇒ Object
Returns the value of attribute lines.
-
.query_type ⇒ Object
Returns the value of attribute query_type.
-
.suppress_logging_of_db_reads ⇒ Object
Returns the value of attribute suppress_logging_of_db_reads.
Class Method Summary collapse
-
.rails_root_regexp ⇒ Object
This cannot be set in a constant as Rails.root is not yet available when this file is loaded.
- .remove_filters_and_silencers(cleaner) ⇒ Object
-
.setup_backtrace_cleaner ⇒ Object
The following code creates a brand new BacktraceCleaner just for the use of this Gem avoiding the dealing with Rails.backtrace_cleaner.
Class Attribute Details
.backtrace_cleaner ⇒ Object
Returns the value of attribute backtrace_cleaner.
32 33 34 |
# File 'lib/active_record_query_trace.rb', line 32 def backtrace_cleaner @backtrace_cleaner end |
.colorize ⇒ Object
Returns the value of attribute colorize.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def colorize @colorize end |
.default_cleaner ⇒ Object
49 50 51 |
# File 'lib/active_record_query_trace.rb', line 49 def default_cleaner @default_cleaner ||= setup_backtrace_cleaner end |
.enabled ⇒ Object
Returns the value of attribute enabled.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def enabled @enabled end |
.ignore_cached_queries ⇒ Object
Returns the value of attribute ignore_cached_queries.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def ignore_cached_queries @ignore_cached_queries end |
.level ⇒ Object
Returns the value of attribute level.
32 33 34 |
# File 'lib/active_record_query_trace.rb', line 32 def level @level end |
.lines ⇒ Object
Returns the value of attribute lines.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def lines @lines end |
.query_type ⇒ Object
Returns the value of attribute query_type.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def query_type @query_type end |
.suppress_logging_of_db_reads ⇒ Object
Returns the value of attribute suppress_logging_of_db_reads.
30 31 32 |
# File 'lib/active_record_query_trace.rb', line 30 def suppress_logging_of_db_reads @suppress_logging_of_db_reads end |
Class Method Details
.rails_root_regexp ⇒ Object
This cannot be set in a constant as Rails.root is not yet available when this file is loaded.
75 76 77 |
# File 'lib/active_record_query_trace.rb', line 75 def rails_root_regexp @rails_root_regexp ||= %r{#{Regexp.escape(Rails.root.to_s)}(?!/vendor)} end |
.remove_filters_and_silencers(cleaner) ⇒ Object
68 69 70 71 |
# File 'lib/active_record_query_trace.rb', line 68 def remove_filters_and_silencers(cleaner) cleaner.remove_filters! cleaner.remove_silencers! end |
.setup_backtrace_cleaner ⇒ Object
The following code creates a brand new BacktraceCleaner just for the use of this Gem avoiding the dealing with Rails.backtrace_cleaner
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_record_query_trace.rb', line 55 def setup_backtrace_cleaner cleaner = Rails::BacktraceCleaner.new remove_filters_and_silencers cleaner cleaner.instance_variable_set :@root, Rails.root.to_s if cleaner.instance_variable_get(:@root) == '/' case ActiveRecordQueryTrace.level when :app cleaner.add_silencer { |line| line !~ rails_root_regexp } when :rails cleaner.add_silencer { |line| line =~ rails_root_regexp } end cleaner end |