Class: Ucode::Repo::BuildReportWriter

Inherits:
Object
  • Object
show all
Includes:
AtomicWrites
Defined in:
lib/ucode/repo/build_report_writer.rb

Overview

Writes the canonical build report (TODO 21) to output/build-report.json atomically and idempotently.

Re-running a build with no changed stats produces zero file writes — the existing build-report.json is byte-compared to the new payload before writing.

The generated_at field is the only non-deterministic part of the report; callers wanting strict idempotency can override the accumulator's to_report to use a fixed timestamp.

Instance Method Summary collapse

Methods included from AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Constructor Details

#initialize(output_root) ⇒ BuildReportWriter

Returns a new instance of BuildReportWriter.

Parameters:

  • output_root (String, Pathname)


24
25
26
# File 'lib/ucode/repo/build_report_writer.rb', line 24

def initialize(output_root)
  @output_root = Pathname.new(output_root)
end

Instance Method Details

#write(report) ⇒ Pathname?

Returns the path written, or nil if the existing file was byte-identical (no-op).

Parameters:

Returns:

  • (Pathname, nil)

    the path written, or nil if the existing file was byte-identical (no-op).



31
32
33
34
35
36
37
# File 'lib/ucode/repo/build_report_writer.rb', line 31

def write(report)
  path = @output_root.join("build-report.json")
  payload = serialize(report)
  return nil unless write_atomic(path, payload)

  path
end