lib/rom/sql/extensions/rails_log_subscriber.rb in rom-sql-3.6.4 vs lib/rom/sql/extensions/rails_log_subscriber.rb in rom-sql-4.0.0.alpha1

- old
+ new

@@ -1,40 +1,25 @@ # frozen_string_literal: true -require 'active_support/log_subscriber' +require "active_support/log_subscriber" module ROM module SQL class RailsLogSubscriber < ActiveSupport::LogSubscriber - as_version = - begin - require "active_support/gem_version" - ActiveSupport.gem_version - rescue LoadError - nil - end - - COLOR_OPTION = - if as_version && as_version >= Gem::Version.new("7.2") - {color: true} - else - true - end - def sql(event) return unless logger.debug? payload = event.payload - name = format('%s (%.1fms)', payload[:name], event.duration) - sql = payload[:sql].squeeze(' ') + name = format("%s (%.1fms)", payload[:name], event.duration) + sql = payload[:sql].squeeze(" ") binds = payload[:binds].to_a.inspect if payload[:binds] if odd? - name = color(name, :cyan, COLOR_OPTION) - sql = color(sql, nil, COLOR_OPTION) + name = color(name, :cyan, true) + sql = color(sql, nil, true) else - name = color(name, :magenta, COLOR_OPTION) + name = color(name, :magenta, true) end debug " #{name} #{sql} #{binds}" end