Class: Moult::FlagsReport

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

Overview

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

Each Finding is one flag key and the call sites referencing it. Without a provider snapshot it carries confidence: null (a flag reference is a recorded fact) and a Moult::Flags::Classification signal — the value_type, reference count, and observed default value(s) — and serializes at schema_version 1.

When a provider snapshot is merged (the static<->provider merge) each finding ALSO carries a confidence-graded Moult::Flags::Staleness candidate (status + confidence + reasons), the report carries an analysis.provider provenance block, and the summary a by_staleness_status tally; the envelope reports schema_version 2. The bump is purely additive: with no snapshot the v2-only blocks are omitted and the output is byte-for-byte identical to v1. The snapshot is evidence, never proof — nothing here asserts a flag is certainly stale or dead.

Defined Under Namespace

Classes: Finding, Occurrence

Constant Summary collapse

SCHEMA_VERSION =

The serialized shape's two additive versions. v1 = usage only; v2 = usage + joined staleness candidates (--provider). Bump either only on a breaking change.

1
SCHEMA_VERSION_WITH_PROVIDER =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, findings:, dynamic_references: 0, git_ref: nil, generated_at: nil, provider_source: nil) ⇒ FlagsReport

Returns a new instance of FlagsReport.

Parameters:

  • root (String)

    absolute analysis root

  • findings (Array<Finding>)

    ranked, strongest staleness candidate (or most-referenced, without a snapshot) first

  • dynamic_references (Integer) (defaults to: 0)

    flag-evaluation calls whose key was not a literal (counted, not catalogued — a static scan cannot resolve the key)

  • provider_source (Flags::Snapshot::Source, nil) (defaults to: nil)

    provenance of a merged provider snapshot; its presence selects schema_version 2 and the v2-only blocks



70
71
72
73
74
75
76
77
# File 'lib/moult/flags_report.rb', line 70

def initialize(root:, findings:, dynamic_references: 0, git_ref: nil, generated_at: nil, provider_source: nil)
  @root = root
  @findings = findings
  @dynamic_references = dynamic_references
  @git_ref = git_ref
  @generated_at = generated_at
  @provider_source = provider_source
end

Instance Attribute Details

#dynamic_referencesObject (readonly)

Returns the value of attribute dynamic_references.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def dynamic_references
  @dynamic_references
end

#findingsObject (readonly)

Returns the value of attribute findings.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def findings
  @findings
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def git_ref
  @git_ref
end

#provider_sourceObject (readonly)

Returns the value of attribute provider_source.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def provider_source
  @provider_source
end

#rootObject (readonly)

Returns the value of attribute root.



61
62
63
# File 'lib/moult/flags_report.rb', line 61

def root
  @root
end

Instance Method Details

#summaryHash

Returns aggregate counts across all flags.

Returns:

  • (Hash)

    aggregate counts across all flags



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/moult/flags_report.rb', line 80

def summary
  base = {
    flags: findings.size,
    references: findings.sum { |f| f.occurrences.size },
    dynamic_references: dynamic_references,
    by_value_type: tally { |f| f.value_type }
  }
  # v2-only: the staleness-status tally appears only when a snapshot was merged.
  base[:by_staleness_status] = staleness_tally if provider_source
  base
end

#to_hObject



92
93
94
95
96
97
98
99
100
# File 'lib/moult/flags_report.rb', line 92

def to_h
  {
    schema_version: provider_source ? SCHEMA_VERSION_WITH_PROVIDER : SCHEMA_VERSION,
    tool: {name: "moult", version: Moult::VERSION},
    analysis: analysis,
    summary: summary,
    findings: findings.map(&:to_h)
  }
end