Class: Dash::Report::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/report/writer.rb

Overview

Writes one JSON report per run under .dash/reports, so the next deploy has something to compare itself against and CI has something to archive.

A failed deploy is written too, with whatever was measured before it broke: the run an operator most wants to look at afterwards is the one that went wrong.

Constant Summary collapse

GITIGNORE =
"*\n!.gitignore\n".freeze
UNSAFE =

A destination is an operator-supplied string and a command can carry a subcommand, so neither is trusted to be a filename.

/[^\w.-]+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, run:, keep:, directory: Dash::ProjectDirectory.join("reports")) ⇒ Writer

run is the metadata Dash::Cli::Base assembled for this invocation — the same hash the trend rules compared against, so the file and the advice cannot disagree.



20
21
22
23
24
25
# File 'lib/dash/report/writer.rb', line 20

def initialize(report, run:, keep:, directory: Dash::ProjectDirectory.join("reports"))
  @report = report
  @run = run
  @keep = keep
  @directory = directory
end

Instance Attribute Details

#directory ⇒ Object (readonly)

Returns the value of attribute directory.



16
17
18
# File 'lib/dash/report/writer.rb', line 16

def directory
  @directory
end

#keep ⇒ Object (readonly)

Returns the value of attribute keep.



16
17
18
# File 'lib/dash/report/writer.rb', line 16

def keep
  @keep
end

#report ⇒ Object (readonly)

Returns the value of attribute report.



16
17
18
# File 'lib/dash/report/writer.rb', line 16

def report
  @report
end

#run ⇒ Object (readonly)

Returns the value of attribute run.



16
17
18
# File 'lib/dash/report/writer.rb', line 16

def run
  @run
end

Instance Method Details

#write ⇒ Object

Returns the path it wrote, or nil when the operator turned history off.



28
29
30
31
32
33
34
35
36
# File 'lib/dash/report/writer.rb', line 28

def write
  return if keep.zero?

  prepare_directory
  @path = publish JSON.pretty_generate(report.to_h(**run))
  Dash::Report::History.new(directory, destination: run[:destination]).prune(keep)

  @path
end