Module: AndOne

Defined in:
lib/and_one.rb,
lib/and_one/dev_ui.rb,
lib/and_one/console.rb,
lib/and_one/railtie.rb,
lib/and_one/version.rb,
lib/and_one/detector.rb,
lib/and_one/matchers.rb,
lib/and_one/aggregate.rb,
lib/and_one/detection.rb,
lib/and_one/dev_toast.rb,
lib/and_one/formatter.rb,
lib/and_one/middleware.rb,
lib/and_one/fingerprint.rb,
lib/and_one/ignore_file.rb,
lib/and_one/scan_helper.rb,
lib/and_one/json_formatter.rb,
lib/and_one/active_job_hook.rb,
lib/and_one/sidekiq_middleware.rb,
lib/and_one/association_resolver.rb

Defined Under Namespace

Modules: ActiveJobHook, AssociationResolver, Console, DevToast, Fingerprint, MinitestHelper, RSpecHelper, ScanHelper Classes: Aggregate, Detection, Detector, DevUI, Formatter, IgnoreFile, JsonFormatter, Middleware, NPlus1Error, Railtie, SidekiqMiddleware, Suggestion

Constant Summary collapse

VERSION =
"0.3.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allow_stack_pathsObject

Returns the value of attribute allow_stack_paths.



15
16
17
# File 'lib/and_one.rb', line 15

def allow_stack_paths
  @allow_stack_paths
end

.backtrace_cleanerObject

Returns the value of attribute backtrace_cleaner.



15
16
17
# File 'lib/and_one.rb', line 15

def backtrace_cleaner
  @backtrace_cleaner
end

.dev_toastObject

Returns the value of attribute dev_toast.



15
16
17
# File 'lib/and_one.rb', line 15

def dev_toast
  @dev_toast
end

.dev_toast_positionObject

Returns the value of attribute dev_toast_position.



15
16
17
# File 'lib/and_one.rb', line 15

def dev_toast_position
  @dev_toast_position
end

.enabledObject

Returns the value of attribute enabled.



15
16
17
# File 'lib/and_one.rb', line 15

def enabled
  @enabled
end

.env_thresholdsObject

Returns the value of attribute env_thresholds.



15
16
17
# File 'lib/and_one.rb', line 15

def env_thresholds
  @env_thresholds
end

.ignore_callersObject

Returns the value of attribute ignore_callers.



15
16
17
# File 'lib/and_one.rb', line 15

def ignore_callers
  @ignore_callers
end

.ignore_file_pathObject

Returns the value of attribute ignore_file_path.



15
16
17
# File 'lib/and_one.rb', line 15

def ignore_file_path
  @ignore_file_path
end

.ignore_queriesObject

Returns the value of attribute ignore_queries.



15
16
17
# File 'lib/and_one.rb', line 15

def ignore_queries
  @ignore_queries
end

.json_loggingObject

Returns the value of attribute json_logging.



15
16
17
# File 'lib/and_one.rb', line 15

def json_logging
  @json_logging
end

.min_n_queriesObject

Returns the value of attribute min_n_queries.



15
16
17
# File 'lib/and_one.rb', line 15

def min_n_queries
  @min_n_queries
end

.notifications_callbackObject

Returns the value of attribute notifications_callback.



15
16
17
# File 'lib/and_one.rb', line 15

def notifications_callback
  @notifications_callback
end

.raise_on_detectObject

Returns the value of attribute raise_on_detect.



15
16
17
# File 'lib/and_one.rb', line 15

def raise_on_detect
  @raise_on_detect
end

Class Method Details

.aggregateObject



88
89
90
91
92
# File 'lib/and_one.rb', line 88

def aggregate
  @singleton_mutex.synchronize do
    @aggregate ||= Aggregate.new
  end
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (AndOne)

    the object that the method was called on



21
22
23
# File 'lib/and_one.rb', line 21

def configure
  yield self
end

.enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/and_one.rb', line 25

def enabled?
  @enabled != false
end

.finishObject



53
54
55
56
57
58
59
60
# File 'lib/and_one.rb', line 53

def finish
  return [] unless scanning?

  detections = detector.finish
  stop_scan
  report(detections) if detections.any?
  detections
end

.ignore_listObject



94
95
96
97
98
# File 'lib/and_one.rb', line 94

def ignore_list
  @singleton_mutex.synchronize do
    @ignore_list ||= IgnoreFile.new(resolve_ignore_file_path)
  end
end

.pauseObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/and_one.rb', line 66

def pause
  if block_given?
    was_scanning = scanning?
    thread_state[:and_one_paused] = true
    begin
      yield
    ensure
      thread_state[:and_one_paused] = false if was_scanning
    end
  else
    thread_state[:and_one_paused] = true
  end
end

.paused?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/and_one.rb', line 84

def paused?
  !!thread_state[:and_one_paused]
end

.reload_ignore_file!Object

Reset cached ignore file (useful after config change)



101
102
103
104
105
# File 'lib/and_one.rb', line 101

def reload_ignore_file!
  @singleton_mutex.synchronize do
    @ignore_list = nil
  end
end

.resumeObject



80
81
82
# File 'lib/and_one.rb', line 80

def resume
  thread_state[:and_one_paused] = false
end

.scanObject

Start scanning for N+1 queries on the current thread. Can be used with a block or as start/finish pair.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/and_one.rb', line 31

def scan
  return block_given? ? yield : nil unless enabled?
  return block_given? ? yield : nil if scanning?

  start_scan

  return unless block_given?

  begin
    yield
    detections = detector.finish
    stop_scan
    report(detections) if detections.any?
    detections
  rescue Exception # rubocop:disable Lint/RescueException
    # On error, clean up without reporting — don't add noise to real errors
    detector&.send(:unsubscribe)
    stop_scan
    raise
  end
end

.scanning?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/and_one.rb', line 62

def scanning?
  !!thread_state[:and_one_detector]
end