Class: RailsConsolePro::CompareResult
- Inherits:
-
Object
- Object
- RailsConsolePro::CompareResult
- Defined in:
- lib/rails_console_pro/compare_result.rb
Overview
Value object for query comparison results
Defined Under Namespace
Classes: Comparison
Instance Attribute Summary collapse
-
#comparisons ⇒ Object
readonly
Returns the value of attribute comparisons.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#winner ⇒ Object
readonly
Returns the value of attribute winner.
Instance Method Summary collapse
- #error_count ⇒ Object
-
#export_to_file(file_path, format: nil) ⇒ Object
Export to file.
- #fastest ⇒ Object
- #fastest_name ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(comparisons:, winner: nil, timestamp: Time.current) ⇒ CompareResult
constructor
A new instance of CompareResult.
- #performance_ratio ⇒ Object
- #slowest ⇒ Object
- #slowest_name ⇒ Object
-
#to_html(style: :default) ⇒ Object
Export to HTML.
-
#to_json(pretty: true) ⇒ Object
Export to JSON.
-
#to_yaml ⇒ Object
Export to YAML.
- #total_queries ⇒ Object
Constructor Details
#initialize(comparisons:, winner: nil, timestamp: Time.current) ⇒ CompareResult
19 20 21 22 23 |
# File 'lib/rails_console_pro/compare_result.rb', line 19 def initialize(comparisons:, winner: nil, timestamp: Time.current) @comparisons = Array(comparisons) @winner = winner = end |
Instance Attribute Details
#comparisons ⇒ Object (readonly)
Returns the value of attribute comparisons.
17 18 19 |
# File 'lib/rails_console_pro/compare_result.rb', line 17 def comparisons @comparisons end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/rails_console_pro/compare_result.rb', line 17 def end |
#winner ⇒ Object (readonly)
Returns the value of attribute winner.
17 18 19 |
# File 'lib/rails_console_pro/compare_result.rb', line 17 def winner @winner end |
Instance Method Details
#error_count ⇒ Object
37 38 39 |
# File 'lib/rails_console_pro/compare_result.rb', line 37 def error_count comparisons.count { |c| c.error } end |
#export_to_file(file_path, format: nil) ⇒ Object
Export to file
76 77 78 |
# File 'lib/rails_console_pro/compare_result.rb', line 76 def export_to_file(file_path, format: nil) FormatExporter.export_to_file(self, file_path, format: format) end |
#fastest ⇒ Object
25 26 27 |
# File 'lib/rails_console_pro/compare_result.rb', line 25 def fastest comparisons.min_by { |c| c.duration_ms || Float::INFINITY } end |
#fastest_name ⇒ Object
45 46 47 |
# File 'lib/rails_console_pro/compare_result.rb', line 45 def fastest_name fastest&.name end |
#has_errors? ⇒ Boolean
33 34 35 |
# File 'lib/rails_console_pro/compare_result.rb', line 33 def has_errors? comparisons.any? { |c| c.error } end |
#performance_ratio ⇒ Object
53 54 55 56 57 58 |
# File 'lib/rails_console_pro/compare_result.rb', line 53 def performance_ratio return nil if comparisons.size < 2 || fastest.nil? || slowest.nil? return nil if fastest.duration_ms.nil? || slowest.duration_ms.nil? || fastest.duration_ms.zero? (slowest.duration_ms / fastest.duration_ms).round(2) end |
#slowest ⇒ Object
29 30 31 |
# File 'lib/rails_console_pro/compare_result.rb', line 29 def slowest comparisons.max_by { |c| c.duration_ms || 0 } end |
#slowest_name ⇒ Object
49 50 51 |
# File 'lib/rails_console_pro/compare_result.rb', line 49 def slowest_name slowest&.name end |
#to_html(style: :default) ⇒ Object
Export to HTML
71 72 73 |
# File 'lib/rails_console_pro/compare_result.rb', line 71 def to_html(style: :default) FormatExporter.to_html(self, title: "Query Comparison", style: style) end |
#to_json(pretty: true) ⇒ Object
Export to JSON
61 62 63 |
# File 'lib/rails_console_pro/compare_result.rb', line 61 def to_json(pretty: true) FormatExporter.to_json(self, pretty: pretty) end |
#to_yaml ⇒ Object
Export to YAML
66 67 68 |
# File 'lib/rails_console_pro/compare_result.rb', line 66 def to_yaml FormatExporter.to_yaml(self) end |
#total_queries ⇒ Object
41 42 43 |
# File 'lib/rails_console_pro/compare_result.rb', line 41 def total_queries comparisons.sum { |c| c.query_count || 0 } end |