Class: RenderGuardian::Report
- Inherits:
-
Object
- Object
- RenderGuardian::Report
- Defined in:
- lib/render_guardian/report.rb
Instance Attribute Summary collapse
-
#budget ⇒ Object
readonly
Returns the value of attribute budget.
-
#helper_findings ⇒ Object
readonly
Returns the value of attribute helper_findings.
-
#n_plus_one_findings ⇒ Object
readonly
Returns the value of attribute n_plus_one_findings.
-
#profiler ⇒ Object
readonly
Returns the value of attribute profiler.
Instance Method Summary collapse
-
#initialize(budget, profiler, n_plus_one_findings, helper_findings) ⇒ Report
constructor
A new instance of Report.
- #summary ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(budget, profiler, n_plus_one_findings, helper_findings) ⇒ Report
Returns a new instance of Report.
7 8 9 10 11 12 |
# File 'lib/render_guardian/report.rb', line 7 def initialize(budget, profiler, n_plus_one_findings, helper_findings) @budget = budget @profiler = profiler @n_plus_one_findings = n_plus_one_findings @helper_findings = helper_findings end |
Instance Attribute Details
#budget ⇒ Object (readonly)
Returns the value of attribute budget.
5 6 7 |
# File 'lib/render_guardian/report.rb', line 5 def budget @budget end |
#helper_findings ⇒ Object (readonly)
Returns the value of attribute helper_findings.
5 6 7 |
# File 'lib/render_guardian/report.rb', line 5 def helper_findings @helper_findings end |
#n_plus_one_findings ⇒ Object (readonly)
Returns the value of attribute n_plus_one_findings.
5 6 7 |
# File 'lib/render_guardian/report.rb', line 5 def n_plus_one_findings @n_plus_one_findings end |
#profiler ⇒ Object (readonly)
Returns the value of attribute profiler.
5 6 7 |
# File 'lib/render_guardian/report.rb', line 5 def profiler @profiler end |
Instance Method Details
#summary ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/render_guardian/report.rb', line 14 def summary { total_renders: @profiler.events.size, templates: @profiler.stats_by_template.size, slow_templates: @profiler.slow_templates.size, slow_partials: @profiler.slow_partials.size, n_plus_one_issues: @n_plus_one_findings.size, slow_helpers: @helper_findings.size } end |
#to_h ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/render_guardian/report.rb', line 25 def to_h { summary: summary, template_stats: @profiler.stats_by_template, partial_stats: @profiler.stats_by_partial, n_plus_one: @n_plus_one_findings, helpers: @helper_findings } end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/render_guardian/report.rb', line 35 def to_s lines = [] lines << "=== Render Guardian Report ===" s = summary lines << "Renders: #{s[:total_renders]} | Templates: #{s[:templates]}" lines << "Slow templates: #{s[:slow_templates]} | Slow partials: #{s[:slow_partials]}" lines << "N+1 issues: #{s[:n_plus_one_issues]} | Slow helpers: #{s[:slow_helpers]}" lines << "" if @n_plus_one_findings.any? lines << "--- N+1 Issues ---" @n_plus_one_findings.each { |f| lines << " [#{f[:severity].upcase}] #{f[:message]}" } lines << "" end if @helper_findings.any? lines << "--- Slow Helpers ---" @helper_findings.each { |f| lines << " [#{f[:severity].upcase}] #{f[:message]}" } lines << "" end if s[:slow_templates].zero? && s[:n_plus_one_issues].zero? && s[:slow_helpers].zero? lines << "✅ All renders within budget!" end lines.join("\n") end |