Class: ActiveRecordQueryCount::Printer::Html

Inherits:
Base
  • Object
show all
Defined in:
lib/active_record_query_count/printer/html.rb

Constant Summary

Constants inherited from Base

Base::BASE_QUERY_COUNTER_PATH, Base::CHART_JS_CONTENT, Base::CSS_PATH, Base::INJECT_TEMPLATE_PATH, Base::JS_PATH, Base::TEMPLATE_COMPARING_PATH, Base::TEMPLATE_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#base_query_counter_content, #chart_js_content, #css_content, #filter_data, #inject_template_content, #js_content, #open_file, #sort_data, #template_comparing_content, #template_content

Constructor Details

#initialize(data:) ⇒ Html

Returns a new instance of Html.



12
13
14
# File 'lib/active_record_query_count/printer/html.rb', line 12

def initialize data:
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/active_record_query_count/printer/html.rb', line 10

def data
  @data
end

Instance Method Details

#chart_dataObject



16
17
18
# File 'lib/active_record_query_count/printer/html.rb', line 16

def chart_data
  @chart_data ||= generate_chart_js_data(data)
end

#inject_in_htmlObject



32
33
34
# File 'lib/active_record_query_count/printer/html.rb', line 32

def inject_in_html
  ERB.new(inject_template_content).result(binding)
end


40
41
42
43
# File 'lib/active_record_query_count/printer/html.rb', line 40

def print
  html_dest = generate_html(binding)
  open_file(html_dest)
end

#render_query_counter_base_divObject



36
37
38
# File 'lib/active_record_query_count/printer/html.rb', line 36

def render_query_counter_base_div
  ERB.new(base_query_counter_content).result(binding)
end

#total_duration_timeObject



24
25
26
27
28
29
30
# File 'lib/active_record_query_count/printer/html.rb', line 24

def total_duration_time
  @total_duration_time ||= data.sum do |_, info|
    info[:location].sum do |_, detail|
      detail[:duration]
    end
  end.truncate(2)
end

#total_query_countObject



20
21
22
# File 'lib/active_record_query_count/printer/html.rb', line 20

def total_query_count
  @total_query_count ||= data.values.sum { |v| v[:count] }
end