Class: Moult::CoverageReport
- Inherits:
-
Object
- Object
- Moult::CoverageReport
- Defined in:
- lib/moult/coverage_report.rb
Overview
The serialized result model for moult coverage (schema/coverage.schema.json):
a per-symbol hot/cold/untracked map. It is a diagnostic view over the same
runtime evidence moult deadcode --coverage folds into confidence — it makes
no dead-code claim, it only reports what ran.
CoverageReport.build is the orchestration: ask the Index for every definition and classify each through Moult::Coverage::Resolver, joined on the same path + span that make up its symbol_id.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#backend_version ⇒ Object
readonly
Returns the value of attribute backend_version.
-
#coverage_source ⇒ Object
readonly
Returns the value of attribute coverage_source.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#generated_at ⇒ Object
readonly
Returns the value of attribute generated_at.
-
#git_ref ⇒ Object
readonly
Returns the value of attribute git_ref.
-
#resolved ⇒ Object
readonly
Returns the value of attribute resolved.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root:, entries:, git_ref: nil, generated_at: nil, backend: "rubydex", backend_version: nil, resolved: true, diagnostics: [], coverage_source: nil) ⇒ CoverageReport
constructor
A new instance of CoverageReport.
-
#summary ⇒ Hash{Symbol=>Integer}
Counts keyed :hot, :cold, :untracked.
- #to_h ⇒ Object
Constructor Details
#initialize(root:, entries:, git_ref: nil, generated_at: nil, backend: "rubydex", backend_version: nil, resolved: true, diagnostics: [], coverage_source: nil) ⇒ CoverageReport
Returns a new instance of CoverageReport.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/moult/coverage_report.rb', line 57 def initialize(root:, entries:, git_ref: nil, generated_at: nil, backend: "rubydex", backend_version: nil, resolved: true, diagnostics: [], coverage_source: nil) @root = root @entries = entries @git_ref = git_ref @generated_at = generated_at @backend = backend @backend_version = backend_version @resolved = resolved @diagnostics = diagnostics @coverage_source = coverage_source end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def backend @backend end |
#backend_version ⇒ Object (readonly)
Returns the value of attribute backend_version.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def backend_version @backend_version end |
#coverage_source ⇒ Object (readonly)
Returns the value of attribute coverage_source.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def coverage_source @coverage_source end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def diagnostics @diagnostics end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def entries @entries end |
#generated_at ⇒ Object (readonly)
Returns the value of attribute generated_at.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def generated_at @generated_at end |
#git_ref ⇒ Object (readonly)
Returns the value of attribute git_ref.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def git_ref @git_ref end |
#resolved ⇒ Object (readonly)
Returns the value of attribute resolved.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def resolved @resolved end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
23 24 25 |
# File 'lib/moult/coverage_report.rb', line 23 def root @root end |
Class Method Details
.build(index:, coverage:, root:, git_ref: nil, generated_at: nil, backend_version: nil) ⇒ CoverageReport
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/moult/coverage_report.rb', line 29 def self.build(index:, coverage:, root:, git_ref: nil, generated_at: nil, backend_version: nil) entries = index.definitions.map do |d| Entry.new( symbol_id: d.symbol_id, kind: d.kind, name: d.name, span: d.span, runtime: Coverage::Resolver.classify(coverage, path: d.path, span: d.span, kind: d.kind) ) end # Hot first (most surprising/actionable), then cold, then untracked; name # as a deterministic tie-break. order = {hot: 0, cold: 1, untracked: 2} entries.sort_by! { |e| [order.fetch(e.runtime, 3), e.name.to_s] } new( root: root, entries: entries, git_ref: git_ref, generated_at: generated_at, backend: "rubydex", backend_version: backend_version, resolved: index.resolved?, diagnostics: index.diagnostics, coverage_source: coverage.source ) end |
Instance Method Details
#summary ⇒ Hash{Symbol=>Integer}
Returns counts keyed :hot, :cold, :untracked.
71 72 73 74 75 |
# File 'lib/moult/coverage_report.rb', line 71 def summary counts = {hot: 0, cold: 0, untracked: 0} entries.each { |e| counts[e.runtime] = counts.fetch(e.runtime, 0) + 1 } counts end |
#to_h ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/moult/coverage_report.rb', line 77 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, index: { backend: backend, backend_version: backend_version, resolved: resolved, diagnostics: diagnostics } }, summary: summary, symbols: entries.map(&:to_h) } end |