Class: QueryMatchers::QueryCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/query_matchers/query_counter.rb

Constant Summary collapse

OPERATIONS =
%w(SELECT INSERT UPDATE DELETE)
RAILS5_INFORMATION_SCHEMA_REGEX =
/^\s*SELECT.+FROM information_schema\./m

Instance Method Summary collapse

Constructor Details

#initializeQueryCounter

Returns a new instance of QueryCounter.



6
7
8
# File 'lib/query_matchers/query_counter.rb', line 6

def initialize
  @events = []
end

Instance Method Details

#execute!(target) ⇒ Object



10
11
12
# File 'lib/query_matchers/query_counter.rb', line 10

def execute!(target)
  ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record', &target)
end

#queriesObject



18
19
20
# File 'lib/query_matchers/query_counter.rb', line 18

def queries
  @events.map {|event| event.payload[:sql] }
end

#query_countObject



14
15
16
# File 'lib/query_matchers/query_counter.rb', line 14

def query_count
  @events.size
end