Class: ActiveRecordQueryCount::Printer::Html

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#css_content, #filter_data, #js_content, #open_file, #sort_data

Constructor Details

#initialize(data:) ⇒ Html

Returns a new instance of Html.



12
13
14
15
16
17
18
19
20
# File 'lib/active_record_query_count/printer/html.rb', line 12

def initialize data:
  @template_path = File.join(__dir__, 'templates', 'template.html.erb')
  @base_query_counter_path = File.join(__dir__, 'templates', 'template_base_query_counter.html.erb')
  @inject_template_path = File.join(__dir__, 'templates', 'template_for_inject.html.erb')
  @css_path = File.join(__dir__, 'templates', 'style.css')
  # este no falla, quizá pueda poner lo mismo aquí con chart.js y así no hacer lo del nonce y csp
  @js_path = File.join(__dir__, 'templates', 'bar_chart.js')
  @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



22
23
24
# File 'lib/active_record_query_count/printer/html.rb', line 22

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

#inject_in_htmlObject



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

def inject_in_html
  ERB.new(File.read(@inject_template_path)).result(binding)
end


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

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

#render_query_counter_base_divObject



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

def render_query_counter_base_div
  ERB.new(File.read(@base_query_counter_path)).result(binding)
end

#total_query_countObject

maybe this should not be filtered



27
28
29
# File 'lib/active_record_query_count/printer/html.rb', line 27

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