class Rectify::RSpec::DatabaseReporter::QueryStats

Attributes

stats[R]

Public Class Methods

new() click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 5
def initialize
  @stats = Hash.new { |h, k| h[k] = [] }
end

Public Instance Methods

add(example, start, finish, query) click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 9
def add(example, start, finish, query)
  info = QueryInfo.new(example, start, finish, query)
  return if info.ignore?

  stats[info.target] << info
end
each() { |target, first.type, count, sum(&:time).round(5)| ... } click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 16
def each
  stats.sort.each do |target, infos|
    yield(
      target,
      infos.first.type,
      infos.count,
      infos.sum(&:time).round(5)
    )
  end
end
empty?() click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 41
def empty?
  stats.empty?
end
longest_target() click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 35
def longest_target
  return 0 if stats.empty?

  stats.keys.max_by(&:length).length
end
total_queries() click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 27
def total_queries
  stats.values.flatten.count
end
total_time() click to toggle source
# File lib/rectify/rspec/database_reporter/query_stats.rb, line 31
def total_time
  stats.values.flatten.sum(&:time).round(5)
end