Module: RailsSqlCounter

Defined in:
lib/rails_sql_counter.rb,
lib/rails_sql_counter/version.rb

Overview

Count sql queries

Constant Summary collapse

VERSION =
'0.2.0'.freeze

Class Method Summary collapse

Class Method Details

.counterObject



46
47
48
# File 'lib/rails_sql_counter.rb', line 46

def self.counter
  Thread.current[:rails_sql_counter]
end

.endObject



41
42
43
44
# File 'lib/rails_sql_counter.rb', line 41

def self.end
  ActiveSupport::Notifications.unsubscribe(@@subscriber)
  @@subscriber = nil
end

.profile(&block) ⇒ Object



34
35
36
37
38
39
# File 'lib/rails_sql_counter.rb', line 34

def self.profile(&block)
  start
  block.call
ensure
  self.end
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



11
12
13
# File 'lib/rails_sql_counter.rb', line 11

def self.setup
  yield self
end

.startObject



26
27
28
29
30
31
32
# File 'lib/rails_sql_counter.rb', line 26

def self.start
  Thread.current[:rails_sql_counter] = 0

  @@subscriber ||= ActiveSupport::Notifications.subscribe('sql.active_record') do |event|
    process(event)
  end
end