Class: Rack::DevInsight::Result::Sql::CrudAggregations
- Inherits:
-
Object
- Object
- Rack::DevInsight::Result::Sql::CrudAggregations
- Defined in:
- lib/rack/dev_insight/result/sql/crud_aggregations.rb
Defined Under Namespace
Classes: CrudAggregation
Instance Method Summary collapse
- #add(dialect_name, statement, duration, query_id) ⇒ Object
- #attributes ⇒ Object
-
#initialize ⇒ CrudAggregations
constructor
A new instance of CrudAggregations.
Constructor Details
#initialize ⇒ CrudAggregations
Returns a new instance of CrudAggregations.
10 11 12 13 |
# File 'lib/rack/dev_insight/result/sql/crud_aggregations.rb', line 10 def initialize @id = 0 @cached_data = {} end |
Instance Method Details
#add(dialect_name, statement, duration, query_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/dev_insight/result/sql/crud_aggregations.rb', line 15 def add(dialect_name, statement, duration, query_id) crud_tables = Extractor.extract_crud_tables(dialect_name, statement) crud_tables.each do |type, tables| tables.each do |table| key = "#{type}_#{table}" data = @cached_data[key] ||= CrudAggregation.new(@id += 1, type, table, 0, 0, []) data.count += 1 data.duration += duration data.query_ids << query_id end end end |
#attributes ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rack/dev_insight/result/sql/crud_aggregations.rb', line 29 def attributes @cached_data.values.map do |data| data.duration = format('%.2f', data.duration).to_f data.to_h end end |