Class: TestProf::Autopilot::ReportWriter

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/test_prof/autopilot/report_writer.rb

Overview

Base class for report writers classes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

log

Constructor Details

#initialize(report) ⇒ ReportWriter

Returns a new instance of ReportWriter.



17
18
19
# File 'lib/test_prof/autopilot/report_writer.rb', line 17

def initialize(report)
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



15
16
17
# File 'lib/test_prof/autopilot/report_writer.rb', line 15

def report
  @report
end

Class Method Details

.write_report(report, **options) ⇒ Object



10
11
12
# File 'lib/test_prof/autopilot/report_writer.rb', line 10

def write_report(report, **options)
  new(report).write(**options)
end

Instance Method Details

#generate_jsonObject



36
37
# File 'lib/test_prof/autopilot/report_writer.rb', line 36

def generate_json
end

#write(file_name: nil, format: "json") ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/test_prof/autopilot/report_writer.rb', line 21

def write(file_name: nil, format: "json")
  file_path = file_name || self.class::ARTIFACT_FILE

  if File.absolute_path?(file_path)
    FileUtils.mkdir_p(File.dirname(file_path))
  else
    dir_path = FileUtils.mkdir_p(Autopilot.config.artifacts_dir)[0]
    file_path = File.join(dir_path, file_path + ".#{format}")
  end

  File.write(file_path, public_send("generate_#{format}"))

  log "Report saved: #{file_path}"
end