123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::StructuredEventSubscriber

Do not use. This class is for internal use only.

Constant Summary

::ActiveSupport::StructuredEventSubscriber - Inherited

DEBUG_CHECK

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

This class inherits a constructor from ActiveSupport::StructuredEventSubscriber

Instance Method Details

#filter(name, value) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 78

def filter(name, value)
  ActiveRecord::Base.inspection_filter.filter_param(name, value)
end

#render_bind(attr, value) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 63

def render_bind(attr, value)
  case attr
  when ActiveModel::Attribute
    if attr.type.binary? && attr.value
      value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
    end
  when Array
    attr = attr.first
  else
    attr = nil
  end

  [attr&.name, value]
end

#sql(event)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 21

def sql(event)
  payload = event.payload

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

  binds = nil

  if payload[:binds]&.any?
    casted_params = type_casted_binds(payload[:type_casted_binds])

    binds = []
    payload[:binds].each_with_index do |attr, i|
      attribute_name = if attr.respond_to?(:name)
        attr.name
      elsif attr.respond_to?(:[]) && attr[i].respond_to?(:name)
        attr[i].name
      else
        nil
      end

      filtered_params = filter(attribute_name, casted_params[i])

      binds << render_bind(attr, filtered_params)
    end
  end

  emit_debug_event("active_record.sql",
    async: payload[:async],
    name: payload[:name],
    sql: payload[:sql],
    cached: payload[:cached],
    lock_wait: payload[:lock_wait],
    binds: binds,
  )
end

#strict_loading_violation(event)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 9

def strict_loading_violation(event)
  owner = event.payload[:owner]
  reflection = event.payload[:reflection]

  emit_debug_event("active_record.strict_loading_violation",
    owner: owner.name,
    class: reflection.klass.name,
    name: reflection.name,
  )
end

#type_casted_binds(casted_binds) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 59

def type_casted_binds(casted_binds)
  casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds
end