Class: MetricFu::Report
- Inherits:
-
Object
- Object
- MetricFu::Report
- Defined in:
- lib/base/report.rb
Overview
Report
The Report class is responsible two things:
It adds information to the yaml report, produced by the system as a whole, for each of the generators used in this test run.
It also handles passing the information from each generator used in this test run out to the template class set in MetricFu::Configuration.
Instance Method Summary collapse
-
#add(report_type) ⇒ Object
Adds a hash from a passed report, produced by one of the Generator classes to the aggregate report_hash managed by this hash.
-
#open_in_browser? ⇒ Boolean
Checks to discover whether we should try and open the results of the report in the browser on this system.
- #per_file_data ⇒ Object
-
#report_hash ⇒ Object
:nodoc:.
-
#save_output(content, dir, file = 'index.html') ⇒ Object
Saves the passed in content to the passed in directory.
-
#save_templatized_report ⇒ Object
Instantiates a new template class based on the configuration set in MetricFu::Configuration, or through the MetricFu.config block in your rake file (defaults to the included AwesomeTemplate), assigns the report_hash to the report_hash in the template, and tells the template to to write itself out.
-
#show_in_browser(dir) ⇒ Object
Shows ‘index.html’ from the passed directory in the browser if we’re able to open the browser on this platform.
-
#to_yaml ⇒ Object
Renders the result of the report_hash into a yaml serialization ready for writing out to a file.
Instance Method Details
#add(report_type) ⇒ Object
Adds a hash from a passed report, produced by one of the Generator classes to the aggregate report_hash managed by this hash.
56 57 58 59 60 61 62 63 |
# File 'lib/base/report.rb', line 56 def add(report_type) clazz = MetricFu.const_get(report_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }) inst = clazz.new report_hash.merge!(inst.generate_report) inst.per_file_info(per_file_data) if inst.respond_to?(:per_file_info) end |
#open_in_browser? ⇒ Boolean
Checks to discover whether we should try and open the results of the report in the browser on this system. We only try and open in the browser if we’re on OS X and we’re not running in a CruiseControl.rb environment. See MetricFu.configuration for more details about how we make those guesses.
93 94 95 96 |
# File 'lib/base/report.rb', line 93 def open_in_browser? MetricFu.configuration.platform.include?('darwin') && ! MetricFu.configuration.is_cruise_control_rb? end |
#per_file_data ⇒ Object
31 32 33 |
# File 'lib/base/report.rb', line 31 def per_file_data @per_file_data ||= {} end |
#report_hash ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/base/report.rb', line 35 def report_hash #:nodoc: @report_hash ||= {} end |
#save_output(content, dir, file = 'index.html') ⇒ Object
Saves the passed in content to the passed in directory. If a filename is passed in it will be used as the name of the file, otherwise it will default to ‘index.html’
79 80 81 82 83 |
# File 'lib/base/report.rb', line 79 def save_output(content, dir, file='index.html') open("#{dir}/#{file}", "w") do |f| f.puts content end end |
#save_templatized_report ⇒ Object
Instantiates a new template class based on the configuration set in MetricFu::Configuration, or through the MetricFu.config block in your rake file (defaults to the included AwesomeTemplate), assigns the report_hash to the report_hash in the template, and tells the template to to write itself out.
44 45 46 47 48 49 |
# File 'lib/base/report.rb', line 44 def save_templatized_report @template = MetricFu.template_class.new @template.report = report_hash @template.per_file_data = per_file_data @template.write end |
#show_in_browser(dir) ⇒ Object
Shows ‘index.html’ from the passed directory in the browser if we’re able to open the browser on this platform.
104 105 106 |
# File 'lib/base/report.rb', line 104 def show_in_browser(dir) system("open #{dir}/index.html") if open_in_browser? end |
#to_yaml ⇒ Object
Renders the result of the report_hash into a yaml serialization ready for writing out to a file.
27 28 29 |
# File 'lib/base/report.rb', line 27 def to_yaml report_hash.to_yaml end |