class ROM::Plugins::Relation::SQL::Instrumentation::Instrumenter

This stateful module is used to extend database connection objects and monkey-patches ‘log_connection_yield` method, which unfortunately is the only way to provide instrumentation on the sequel side.

@api private

Attributes

name[R]

@!attribute [r] name

@return [Symbol] database type
notifications[R]

@!attribute [r] notifications

@return [Object] any object that responds to `instrument`

Public Class Methods

new(name, notifications) click to toggle source

@api private

Calls superclass method
# File lib/rom/plugins/relation/sql/instrumentation.rb, line 60
def initialize(name, notifications)
  super()

  @name = name
  @notifications = notifications
  define_log_connection_yield
end

Private Instance Methods

define_log_connection_yield() click to toggle source

@api private

Calls superclass method
# File lib/rom/plugins/relation/sql/instrumentation.rb, line 71
def define_log_connection_yield
  name = self.name
  notifications = self.notifications

  define_method(:rom_instrumentation?) { true }

  define_method(:log_connection_yield) do |*args, &block|
    notifications.instrument(:sql, name: name, query: args[0]) do
      super(*args, &block)
    end
  end
end