Class: NOne::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/n_one/runner.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(whitelist: [], ignore_names: [], stacktrace_sanitizer: nil) ⇒ Runner

Instantiation

Parameters:

  • whitelist (<String>) (defaults to: [])

    frame substrings to be ignored

  • ignore_names (<String>) (defaults to: [])

    query names to be ignored

  • stacktrace_sanitizer (Proc<Array<String>>) (defaults to: nil)

    if given, used to filter the stack trace that is used to calculate the location key



12
13
14
15
16
# File 'lib/n_one/runner.rb', line 12

def initialize(whitelist: [], ignore_names: [], stacktrace_sanitizer: nil)
  @whitelist = ['active_record/validations/uniqueness'] + whitelist
  @ignore_names = ignore_names
  @stacktrace_sanitizer = stacktrace_sanitizer
end

Instance Method Details

#scan(&block) ⇒ Object



18
19
20
21
22
# File 'lib/n_one/runner.rb', line 18

def scan(&block)
  init_store
  record_sql(&block)
  detect_n_plus_ones
end

#scan!(&block) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/n_one/runner.rb', line 24

def scan!(&block)
  report = scan(&block)

  raise NPlusOneDetected, report unless report.empty?
end