Class: WtActiverecordIndexSpy::Aggregator
- Inherits:
-
Object
- Object
- WtActiverecordIndexSpy::Aggregator
- Extended by:
- T::Sig
- Defined in:
- lib/wt_activerecord_index_spy/aggregator.rb
Overview
This class aggregates all queries that were considered not using index. Since it’s not possible to be sure for every query, it separates the result in certains and uncertains.
Defined Under Namespace
Classes: Item
Constant Summary collapse
- Results =
T.type_alias { T::Hash[String, Item] }
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #add(item) ⇒ Object
- #certain_results ⇒ Object
- #export_html_results(file = nil, stdout: $stdout) ⇒ Object
-
#initialize ⇒ Aggregator
constructor
A new instance of Aggregator.
- #reset ⇒ Object
- #uncertain_results ⇒ Object
Constructor Details
#initialize ⇒ Aggregator
27 28 29 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 27 def initialize @results = T.let({}, Results) end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
17 18 19 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 17 def results @results end |
Instance Method Details
#add(item) ⇒ Object
38 39 40 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 38 def add(item) @results[item.query] = item end |
#certain_results ⇒ Object
43 44 45 46 47 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 43 def certain_results @results.map do |_query, item| item if item.certainity_level == :certain end.compact end |
#export_html_results(file = nil, stdout: $stdout) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 64 def export_html_results(file=nil, stdout: $stdout) file ||= default_html_output_file content = ERB.new(File.read(File.join(File.dirname(__FILE__), "./results.html.erb")), 0, "-") .result_with_hash(certain_results: certain_results, uncertain_results: uncertain_results) file.write(content) file.close stdout.puts "Report exported to #{file.path}" end |
#reset ⇒ Object
32 33 34 35 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 32 def reset @results = {} nil end |
#uncertain_results ⇒ Object
50 51 52 53 54 |
# File 'lib/wt_activerecord_index_spy/aggregator.rb', line 50 def uncertain_results @results.map do |_query, item| item if item.certainity_level == :uncertain end.compact end |