Sha256: 3fac0f6ff924b581192987bc73ec63b41df42437c6b50f6c09414f105209703d

Contents?: true

Size: 920 Bytes

Versions: 17

Compression:

Stored size: 920 Bytes

Contents

ActiveRecord::LogSubscriber # rubocop:disable Lint/Void

class ActiveRecord::LogSubscriber # rubocop:disable ClassAndModuleChildren
  def sql(event) # rubocop:disable AbcSize
    self.class.runtime += event.duration

    return unless logger.debug?

    payload = event.payload
    name    = payload[:name]
    return if IGNORE_PAYLOAD_NAMES.include?(name)

    log = {
      message:  name,
      sql:      payload[:sql],
      duration: event.duration,
    }
    unless (payload[:binds] || []).empty?
      log[:binds] = binds = {}
      # Changed with Rails 5
      if Rails.version.to_i >= 5
        payload[:binds].each do |attr|
          attr_name, value = render_bind(attr)
          binds[attr_name] = value
        end
      else
        payload[:binds].each do |col, v|
          attr_name, value = render_bind(col, v)
          binds[attr_name] = value
        end
      end
    end
    debug(log)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sapience-0.2.4 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.2.3 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.2.2 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.2.1 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.2.0 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.13 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.12 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.11 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.10 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.9 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.8 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.7 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.6 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.5 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.4 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.3 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-0.1.2 lib/sapience/extensions/active_record/log_subscriber.rb