class NotificationTracer::SqlFormatter

Attributes

prefix[R]

Public Class Methods

new(prefix: nil) click to toggle source
# File lib/notification_tracer/sql_formatter.rb, line 5
def initialize(prefix: nil)
  @prefix = ensure_non_empty_string(prefix) if prefix
end

Public Instance Methods

call(stack:, sql:, duration:, uuid:) click to toggle source
# File lib/notification_tracer/sql_formatter.rb, line 9
def call(stack:, sql:, duration:, uuid:)
  message  = "Matching Query"
  message  = "#{prefix} | #{message}" if prefix
  message += " | #{duration} ms | ##{uuid}"
  message += "\n ** SQL: " + sql.gsub("\n",'\n')
  ([message] + stack).join("\n  >>> ")
end

Private Instance Methods

ensure_non_empty_string(string) click to toggle source
# File lib/notification_tracer/sql_formatter.rb, line 19
def ensure_non_empty_string(string)
  if string.is_a?(String)
    return string.freeze unless string.empty?
    raise ArgumentError, "prefix should not be empty, use nil instead"
  end
  raise ArgumentError, "expected a String prefix, got: #{string.inspect}"
end