Class: ActiveRecord::QueryCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/dunlop/matchers/exceed_query_limit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueryCounter

Returns a new instance of QueryCounter.



7
8
9
10
# File 'lib/rspec/dunlop/matchers/exceed_query_limit.rb', line 7

def initialize
  @performed_queries = []
  @query_count = 0
end

Instance Attribute Details

#performed_queriesObject (readonly)

Returns the value of attribute performed_queries.



5
6
7
# File 'lib/rspec/dunlop/matchers/exceed_query_limit.rb', line 5

def performed_queries
  @performed_queries
end

#query_countObject (readonly)

Returns the value of attribute query_count.



5
6
7
# File 'lib/rspec/dunlop/matchers/exceed_query_limit.rb', line 5

def query_count
  @query_count
end

Instance Method Details

#callback(name, start, finish, message_id, values) ⇒ Object



16
17
18
19
20
21
# File 'lib/rspec/dunlop/matchers/exceed_query_limit.rb', line 16

def callback(name, start, finish, message_id, values)
  unless %w[ CACHE SCHEMA SAVEPOINT ].include?(values[:name])
    @query_count += 1
    @performed_queries << values[:sql]
  end
end

#to_procObject



12
13
14
# File 'lib/rspec/dunlop/matchers/exceed_query_limit.rb', line 12

def to_proc
  lambda(&method(:callback))
end