Module: PpSql::LogSubscriberPrettyPrint

Includes:
Formatter
Defined in:
lib/pp_sql.rb

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pp_sql.rb', line 65

def sql(event)
  return unless logger.debug?
  self.class.runtime += event.duration

  payload = event.payload

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

  name  = "#{payload[:name]} (#{event.duration.round(1)}ms)"
  sql   = payload[:sql]
  binds = nil

  unless (payload[:binds] || []).empty?
    binds = "  " + payload[:binds].map do |*args|
      method(:render_bind).arity == 1 ? render_bind(args.first) : render_bind(*args)
    end.inspect
  end

  name = colorize_payload_name(name, payload[:name])
  # only this line was rewritten from the AR
  sql  = color(_sql_formatter.format(sql.dup), sql_color(sql), true)

  debug "  #{name}  #{sql}#{binds}"
end