Class: Nunes::Subscribers::ActiveRecord

Inherits:
Nunes::Subscriber show all
Defined in:
lib/nunes/subscribers/active_record.rb

Constant Summary collapse

Pattern =

Private

/\.active_record\Z/
Space =

Private: Used to detect the operation from the sql.

" ".freeze

Constants inherited from Nunes::Subscriber

Nunes::Subscriber::BANG, Nunes::Subscriber::DOT

Instance Attribute Summary

Attributes inherited from Nunes::Subscriber

#adapter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Nunes::Subscriber

#call, #increment, #initialize, subscribe, #timing

Constructor Details

This class inherits a constructor from Nunes::Subscriber

Class Method Details

.patternObject

Private: The namespace for events to subscribe to.



10
11
12
# File 'lib/nunes/subscribers/active_record.rb', line 10

def self.pattern
  Pattern
end

Instance Method Details

#sql(start, ending, transaction_id, payload) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nunes/subscribers/active_record.rb', line 17

def sql(start, ending, transaction_id, payload)
  runtime = ((ending - start) * 1_000).round
  name = payload[:name]
  sql = payload[:sql].to_s.strip
  operation = sql.split(Space, 2).first.to_s.downcase

  timing "active_record.sql", runtime

  case operation
  when "begin"
    timing "active_record.sql.transaction_begin", runtime
  when "commit"
    timing "active_record.sql.transaction_commit", runtime
  else
    timing "active_record.sql.#{operation}", runtime
  end
end