Class: Moult::Report

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

Overview

The in-memory result model and the source of the typed JSON output contract. This is one of Moult's two protected APIs (the other being the per-finding confidence model). Every analysis must be swappable behind this shape without changing it; both formatters render from this object so they cannot drift.

The model reserves confidence and category on every finding even though Phase 1 never populates them: findings are confidence-graded, never asserted as certain death. Phases 2+ fill these in without a schema_version bump.

Defined Under Namespace

Classes: Hotspot, Method

Constant Summary collapse

SCHEMA_VERSION =

Bump only on a breaking change to the serialized shape.

1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, hotspots:, git_ref: nil, generated_at: nil, churn_window: nil, churn_since: nil) ⇒ Report

Returns a new instance of Report.

Parameters:

  • root (String)

    absolute path the analysis was rooted at

  • hotspots (Array<Hotspot>)

    ranked, highest score first

  • git_ref (String, nil) (defaults to: nil)

    HEAD sha when run inside a repo

  • generated_at (String, nil) (defaults to: nil)

    ISO8601 timestamp

  • churn_window (String, nil) (defaults to: nil)

    human description of the churn window

  • churn_since (String, nil) (defaults to: nil)

    the resolved --since boundary (ISO8601 date)



25
26
27
28
29
30
31
32
# File 'lib/moult/report.rb', line 25

def initialize(root:, hotspots:, git_ref: nil, generated_at: nil, churn_window: nil, churn_since: nil)
  @root = root
  @hotspots = hotspots
  @git_ref = git_ref
  @generated_at = generated_at
  @churn_window = churn_window
  @churn_since = churn_since
end

Instance Attribute Details

#churn_sinceObject (readonly)

Returns the value of attribute churn_since.



17
18
19
# File 'lib/moult/report.rb', line 17

def churn_since
  @churn_since
end

#churn_windowObject (readonly)

Returns the value of attribute churn_window.



17
18
19
# File 'lib/moult/report.rb', line 17

def churn_window
  @churn_window
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



17
18
19
# File 'lib/moult/report.rb', line 17

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



17
18
19
# File 'lib/moult/report.rb', line 17

def git_ref
  @git_ref
end

#hotspotsObject (readonly)

Returns the value of attribute hotspots.



17
18
19
# File 'lib/moult/report.rb', line 17

def hotspots
  @hotspots
end

#rootObject (readonly)

Returns the value of attribute root.



17
18
19
# File 'lib/moult/report.rb', line 17

def root
  @root
end

Instance Method Details

#to_hObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/moult/report.rb', line 34

def to_h
  {
    schema_version: SCHEMA_VERSION,
    tool: {name: "moult", version: Moult::VERSION},
    analysis: {
      root: root,
      git_ref: git_ref,
      generated_at: generated_at,
      churn: {window: churn_window, since: churn_since}
    },
    hotspots: hotspots.map(&:to_h)
  }
end