class RSpec::SQLimit::Reporter

Attributes

matcher[R]

Public Class Methods

new(counter) click to toggle source
# File lib/rspec/sqlimit/reporter.rb, line 5
def initialize(counter)
  @counter = counter
  @count   = counter.count
  @queries = counter.queries
  @matcher = counter.matcher
end

Public Instance Methods

call() click to toggle source
# File lib/rspec/sqlimit/reporter.rb, line 12
    def call
      suffix = " among others (see mark ->)" if @matcher
      return "No queries were invoked" if @queries.empty?

      <<-MESSAGE.gsub(/ +\|/, "")
        |The following #{@count} queries were invoked#{suffix}:
        |#{lines.join("\n")}
      MESSAGE
    end

Private Instance Methods

line(query, index) click to toggle source
# File lib/rspec/sqlimit/reporter.rb, line 28
def line(query, index)
  prefix = (matcher && query[:sql] =~ matcher) ? "->" : "  "
  binds = query[:binds]&.any? ? "; #{query[:binds]} " : ""
  "#{prefix} #{index + 1}) #{query[:sql]}#{binds}" \
  " (#{query[:duration].round(3)} ms)"
end
lines() click to toggle source
# File lib/rspec/sqlimit/reporter.rb, line 24
def lines
  @queries.map.with_index { |*args| line(*args) }
end