class ActiveRecord::LogSubscriber
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_record/log_subscriber.rbs class ActiveRecord::LogSubscriber < ActiveRecord::ActiveSupport::LogSubscriber def self.reset_runtime: () -> (Float | Integer) def self.runtime: () -> (Float | Integer) def self.runtime=: ((Float | Integer) value) -> (Float | Integer) def colorize_payload_name: (String name, String? payload_name) -> String def debug: (?String progname, ) -> Integer? def extract_query_source_location: (Array[String] locations) -> String def filter: (String name, String value) -> String def log_query_source: () -> Integer def logger: () -> ActiveSupport::Logger def render_bind: ((ActiveRecord::Relation::QueryAttribute | ActiveModel::Attribute::FromUser) attr, String value) -> Array[String] def sql: (ActiveSupport::Notifications::Event event) -> nil def sql_color: (String sql) -> String def type_casted_binds: (Array[String] casted_binds) -> untyped end
def self.reset_runtime
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.reset_runtime: () -> (Float | Integer)
This signature was generated using 3 samples from 2 applications.
def self.reset_runtime rt, self.runtime = runtime, 0 rt end
def self.runtime
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.runtime: () -> (Float | Integer)
This signature was generated using 54 samples from 1 application.
def self.runtime ActiveRecord::RuntimeRegistry.sql_runtime ||= 0 end
def self.runtime=(value)
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.runtime=: ((Float | Integer) value) -> (Float | Integer)
This signature was generated using 54 samples from 2 applications.
def self.runtime=(value) ActiveRecord::RuntimeRegistry.sql_runtime = value end
def colorize_payload_name(name, payload_name)
Experimental RBS support (using type sampling data from the type_fusion
project).
def colorize_payload_name: (String name, String? payload_name) -> String
This signature was generated using 55 samples from 2 applications.
def colorize_payload_name(name, payload_name) if payload_name.blank? || payload_name == "SQL" # SQL vs Model Load/Exists color(name, MAGENTA, true) else color(name, CYAN, true) end end
def debug(progname = nil, &block)
Experimental RBS support (using type sampling data from the type_fusion
project).
def debug: (?String progname, ) -> Integer?
This signature was generated using 42 samples from 2 applications.
def debug(progname = nil, &block) return unless super if ActiveRecord.verbose_query_logs log_query_source end end
def extract_query_source_location(locations)
Experimental RBS support (using type sampling data from the type_fusion
project).
def extract_query_source_location: (String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String locations) -> String
This signature was generated using 1 sample from 1 application.
def extract_query_source_location(locations) backtrace_cleaner.clean(locations.lazy).first end
def filter(name, value)
Experimental RBS support (using type sampling data from the type_fusion
project).
def filter: (String name, String value) -> String
This signature was generated using 105 samples from 1 application.
def filter(name, value) ActiveRecord::Base.inspection_filter.filter_param(name, value) end
def log_query_source
Experimental RBS support (using type sampling data from the type_fusion
project).
def log_query_source: () -> Integer
This signature was generated using 2 samples from 1 application.
def log_query_source source = extract_query_source_location(caller) if source logger.debug(" ↳ #{source}") end end
def logger
Experimental RBS support (using type sampling data from the type_fusion
project).
def logger: () -> ActiveSupport::Logger
This signature was generated using 243 samples from 2 applications.
def logger ActiveRecord::Base.logger end
def render_bind(attr, value)
Experimental RBS support (using type sampling data from the type_fusion
project).
def render_bind: ((ActiveRecord::Relation::QueryAttribute | ActiveModel::Attribute::FromUser) attr, String value) -> String
This signature was generated using 96 samples from 1 application.
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
def sql(event)
Experimental RBS support (using type sampling data from the type_fusion
project).
def sql: (ActiveSupport::Notifications::Event event) -> nil
This signature was generated using 46 samples from 2 applications.
def sql(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) name = if payload[:async] "ASYNC #{payload[:name]} (#{payload[:lock_wait].round(1)}ms) (db time #{event.duration.round(1)}ms)" else "#{payload[:name]} (#{event.duration.round(1)}ms)" end name = "CACHE #{name}" if payload[:cached] sql = payload[:sql] 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 binds = binds.inspect binds.prepend(" ") end name = colorize_payload_name(name, payload[:name]) sql = color(sql, sql_color(sql), true) if colorize_logging debug " #{name} #{sql}#{binds}" end
def sql_color(sql)
Experimental RBS support (using type sampling data from the type_fusion
project).
def sql_color: (String sql) -> String
This signature was generated using 49 samples from 2 applications.
def sql_color(sql) case sql when /\A\s*rollback/mi RED when /select .*for update/mi, /\A\s*lock/mi WHITE when /\A\s*select/i BLUE when /\A\s*insert/i GREEN when /\A\s*update/i YELLOW when /\A\s*delete/i RED when /transaction\s*\Z/i CYAN else MAGENTA end end
def strict_loading_violation(event)
def strict_loading_violation(event) debug do owner = event.payload[:owner] reflection = event.payload[:reflection] color(reflection.strict_loading_violation_message(owner), RED) end end
def type_casted_binds(casted_binds)
Experimental RBS support (using type sampling data from the type_fusion
project).
def type_casted_binds: ((String | String | String | String | String | String | String | String | String | String | String | String | NilClass) casted_binds) -> untyped
This signature was generated using 17 samples from 1 application.
def type_casted_binds(casted_binds) casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds end