Class: Moult::DuplicationReport

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

Overview

The serialized result model for moult duplication (schema/duplication.schema.json), sibling to DeadCodeReport and CoverageReport. It owns the JSON envelope and leaves the other protected contracts untouched. Each Finding is a confidence- graded clone group carrying its Reasons and Occurrences; nothing here asserts that duplication is certainly removable.

Defined Under Namespace

Classes: Finding, Occurrence

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:, findings:, git_ref: nil, generated_at: nil, backend: "flay", backend_version: nil, min_mass: nil, fuzzy: false) ⇒ DuplicationReport

Returns a new instance of DuplicationReport.

Parameters:

  • root (String)

    absolute analysis root

  • findings (Array<Finding>)

    ranked, highest-confidence first

  • backend (String) (defaults to: "flay")

    detector backend name (e.g. "flay")

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

    backend gem version

  • min_mass (Integer) (defaults to: nil)

    the mass threshold used

  • fuzzy (Boolean) (defaults to: false)

    whether near-matches were included



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/moult/duplication_report.rb', line 48

def initialize(root:, findings:, git_ref: nil, generated_at: nil,
  backend: "flay", backend_version: nil, min_mass: nil, fuzzy: false)
  @root = root
  @findings = findings
  @git_ref = git_ref
  @generated_at = generated_at
  @backend = backend
  @backend_version = backend_version
  @min_mass = min_mass
  @fuzzy = fuzzy
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def backend
  @backend
end

#backend_versionObject (readonly)

Returns the value of attribute backend_version.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def backend_version
  @backend_version
end

#findingsObject (readonly)

Returns the value of attribute findings.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def findings
  @findings
end

#fuzzyObject (readonly)

Returns the value of attribute fuzzy.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def fuzzy
  @fuzzy
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def git_ref
  @git_ref
end

#min_massObject (readonly)

Returns the value of attribute min_mass.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def min_mass
  @min_mass
end

#rootObject (readonly)

Returns the value of attribute root.



39
40
41
# File 'lib/moult/duplication_report.rb', line 39

def root
  @root
end

Instance Method Details

#summaryHash

Returns aggregate counts across all clone groups.

Returns:

  • (Hash)

    aggregate counts across all clone groups



61
62
63
64
65
66
67
# File 'lib/moult/duplication_report.rb', line 61

def summary
  {
    sets: findings.size,
    occurrences: findings.sum { |f| f.occurrences.size },
    total_mass: findings.sum(&:mass)
  }
end

#to_hObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/moult/duplication_report.rb', line 69

def to_h
  {
    schema_version: SCHEMA_VERSION,
    tool: {name: "moult", version: Moult::VERSION},
    analysis: {
      root: root,
      git_ref: git_ref,
      generated_at: generated_at,
      detector: {
        backend: backend,
        backend_version: backend_version,
        min_mass: min_mass,
        fuzzy: fuzzy
      }
    },
    summary: summary,
    findings: findings.map(&:to_h)
  }
end