Class: Rectify::RSpec::DatabaseReporter::QueryStats
- Inherits:
-
Object
- Object
- Rectify::RSpec::DatabaseReporter::QueryStats
- Defined in:
- lib/rectify/rspec/database_reporter/query_stats.rb
Instance Method Summary collapse
- #add(example, start, finish, query) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ QueryStats
constructor
A new instance of QueryStats.
- #longest_target ⇒ Object
- #total_queries ⇒ Object
- #total_time ⇒ Object
Constructor Details
#initialize ⇒ QueryStats
Returns a new instance of QueryStats.
5 6 7 |
# File 'lib/rectify/rspec/database_reporter/query_stats.rb', line 5 def initialize @stats = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#add(example, start, finish, query) ⇒ Object
9 10 11 12 13 14 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# 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? ⇒ Boolean
41 42 43 |
# File 'lib/rectify/rspec/database_reporter/query_stats.rb', line 41 def empty? stats.empty? end |
#longest_target ⇒ Object
35 36 37 38 39 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/rectify/rspec/database_reporter/query_stats.rb', line 27 def total_queries stats.values.flatten.count end |
#total_time ⇒ Object
31 32 33 |
# File 'lib/rectify/rspec/database_reporter/query_stats.rb', line 31 def total_time stats.values.flatten.sum(&:time).round(5) end |