Class: RorVsWild::Plugin::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/plugin/active_record.rb

Constant Summary collapse

IGNORED_QUERIES =
%w[EXPLAIN SCHEMA].freeze
APPENDABLE_QUERIES =
["BEGIN", "COMMIT"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setupObject


4
5
6
7
8
# File 'lib/rorvswild/plugin/active_record.rb', line 4

def self.setup
  return if @installed
  setup_callback
  @installed = true
end

.setup_callbackObject


10
11
12
13
# File 'lib/rorvswild/plugin/active_record.rb', line 10

def self.setup_callback
  return unless defined?(::ActiveSupport::Notifications.subscribe)
  ActiveSupport::Notifications.subscribe("sql.active_record", new)
end

Instance Method Details

#finish(name, id, payload) ⇒ Object


27
28
29
30
# File 'lib/rorvswild/plugin/active_record.rb', line 27

def finish(name, id, payload)
  return if IGNORED_QUERIES.include?(payload[:name])
  RorVsWild::Section.stop
end

#start(name, id, payload) ⇒ Object


18
19
20
21
22
23
24
25
# File 'lib/rorvswild/plugin/active_record.rb', line 18

def start(name, id, payload)
  return if IGNORED_QUERIES.include?(payload[:name])
  RorVsWild::Section.start do |section|
    section.appendable_command = APPENDABLE_QUERIES.include?(payload[:sql])
    section.command = payload[:sql]
    section.kind = "sql".freeze
  end
end