Module: WtActiverecordIndexSpy

Extended by:
WtActiverecordIndexSpy
Included in:
WtActiverecordIndexSpy
Defined in:
lib/wt_activerecord_index_spy.rb,
lib/wt_activerecord_index_spy/version.rb,
lib/wt_activerecord_index_spy/aggregator.rb,
lib/wt_activerecord_index_spy/test_helpers.rb,
lib/wt_activerecord_index_spy/query_analyser.rb,
lib/wt_activerecord_index_spy/query_analyser/mysql.rb,
lib/wt_activerecord_index_spy/notification_listener.rb,
lib/wt_activerecord_index_spy/query_analyser/postgres.rb

Overview

typed: true frozen_string_literal: true

Defined Under Namespace

Modules: TestHelpers Classes: Aggregator, NotificationListener, QueryAnalyser

Constant Summary collapse

VERSION =
"0.5.0"
MissingIndex =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



17
18
19
# File 'lib/wt_activerecord_index_spy.rb', line 17

def logger
  @logger
end

Instance Method Details

#aggregatorObject



19
20
21
# File 'lib/wt_activerecord_index_spy.rb', line 19

def aggregator
  @aggregator ||= Aggregator.new
end

#bootObject



68
69
70
# File 'lib/wt_activerecord_index_spy.rb', line 68

def boot
  @logger = Logger.new("/dev/null")
end

#certain_resultsObject



56
57
58
# File 'lib/wt_activerecord_index_spy.rb', line 56

def certain_results
  aggregator.certain_results
end

#export_html_results(file = nil, stdout: $stdout) ⇒ Object

rubocop:enable Metrics/MethodLength



52
53
54
# File 'lib/wt_activerecord_index_spy.rb', line 52

def export_html_results(file = nil, stdout: $stdout)
  aggregator.export_html_results(file, stdout: stdout)
end

#query_analyserObject



23
24
25
# File 'lib/wt_activerecord_index_spy.rb', line 23

def query_analyser
  @query_analyser ||= QueryAnalyser.new
end

#reset_resultsObject



64
65
66
# File 'lib/wt_activerecord_index_spy.rb', line 64

def reset_results
  aggregator.reset
end

#resultsObject



60
61
62
# File 'lib/wt_activerecord_index_spy.rb', line 60

def results
  aggregator.results
end

#watch_queries(aggregator: self.aggregator, ignore_queries_originated_in_test_code: true, query_analyser: self.query_analyser) ⇒ Object

rubocop:disable Metrics/MethodLength



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

def watch_queries(
  aggregator: self.aggregator,
  ignore_queries_originated_in_test_code: true,
  query_analyser: self.query_analyser
)
  aggregator.reset

  notification_listener = NotificationListener.new(
    aggregator: aggregator,
    ignore_queries_originated_in_test_code: ignore_queries_originated_in_test_code,
    query_analyser: query_analyser
  )

  subscriber = ActiveSupport::Notifications
               .subscribe("sql.active_record", notification_listener)

  return unless block_given?

  yield

  ActiveSupport::Notifications.unsubscribe(subscriber)
end