Class: Moult::HealthReport

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

Overview

The serialized result model for moult health (schema/health.schema.json), sibling to DuplicationReport, DeadCodeReport and CoverageReport. It owns its own JSON envelope and leaves the other protected contracts untouched.

The composite is a confidence-graded health SIGNAL, never a verdict: it records every contributing component (and every skipped/errored one) plus the reasons behind each sub-score, so the headline number is auditable. Nothing here asserts a pass/fail — that gate is Phase 4.

Defined Under Namespace

Classes: ComponentView, FileView

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:, score:, grade:, components:, files:, git_ref: nil, generated_at: nil, coverage_source: nil, churn_window: nil, churn_since: nil) ⇒ HealthReport

Returns a new instance of HealthReport.

Parameters:

  • root (String)

    absolute analysis root

  • score (Float, nil)

    composite health in [0, 1]; nil when no component ran

  • grade (String, nil)

    letter grade, or nil

  • components (Array<ComponentView>)

    one per considered analysis, fixed order

  • files (Array<FileView>)

    per-file roll-up, least-healthy first

  • coverage_source (Coverage::Source, nil) (defaults to: nil)

    provenance when coverage was merged



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/moult/health_report.rb', line 60

def initialize(root:, score:, grade:, components:, files:, git_ref: nil, generated_at: nil,
  coverage_source: nil, churn_window: nil, churn_since: nil)
  @root = root
  @score = score
  @grade = grade
  @components = components
  @files = files
  @git_ref = git_ref
  @generated_at = generated_at
  @coverage_source = coverage_source
  @churn_window = churn_window
  @churn_since = churn_since
end

Instance Attribute Details

#churn_sinceObject (readonly)

Returns the value of attribute churn_since.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def churn_since
  @churn_since
end

#churn_windowObject (readonly)

Returns the value of attribute churn_window.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def churn_window
  @churn_window
end

#componentsObject (readonly)

Returns the value of attribute components.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def components
  @components
end

#coverage_sourceObject (readonly)

Returns the value of attribute coverage_source.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def coverage_source
  @coverage_source
end

#filesObject (readonly)

Returns the value of attribute files.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def files
  @files
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def git_ref
  @git_ref
end

#gradeObject (readonly)

Returns the value of attribute grade.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def grade
  @grade
end

#rootObject (readonly)

Returns the value of attribute root.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def root
  @root
end

#scoreObject (readonly)

Returns the value of attribute score.



51
52
53
# File 'lib/moult/health_report.rb', line 51

def score
  @score
end

Instance Method Details

#to_hObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/moult/health_report.rb', line 74

def to_h
  {
    schema_version: SCHEMA_VERSION,
    tool: {name: "moult", version: Moult::VERSION},
    analysis: {
      root: root,
      git_ref: git_ref,
      generated_at: generated_at,
      coverage: coverage_source&.to_h,
      churn: {window: churn_window, since: churn_since}
    },
    overall: {
      score: score,
      grade: grade,
      components_present: components.count(&:present),
      components_total: components.size,
      files_total: files.size
    },
    components: components.map(&:to_h),
    files: files.map(&:to_h)
  }
end