Class: ActiveRecordQueryStats::Summary

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_query_stats/summary.rb

Constant Summary collapse

STATS =
%i[
  total real cached
  select insert update delete
  transaction savepoint lock rollback other
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSummary

Returns a new instance of Summary.



15
16
17
18
19
# File 'lib/active_record_query_stats/summary.rb', line 15

def initialize
  STATS.each do |field|
    instance_variable_set :"@#{field}", 0
  end
end

Class Method Details

.callObject



11
12
13
# File 'lib/active_record_query_stats/summary.rb', line 11

def self.call
  RequestStore[:active_record_query_stats] ||= new
end

Instance Method Details

#to_payloadObject



31
32
33
34
35
# File 'lib/active_record_query_stats/summary.rb', line 31

def to_payload
  STATS.each_with_object({}) do |field, memo|
    memo[field] = try field
  end
end