Class: Moult::CyclesReport

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

Overview

The serialized result model for moult cycles (schema/cycles.schema.json), sibling to DuplicationReport and DeadCodeReport. Each Finding is one strongly-connected component of the file dependency graph, carrying the resolved constant-reference edges as its evidence.

Defined Under Namespace

Classes: Finding

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: "rubydex", backend_version: nil, resolved: true, diagnostics: []) ⇒ CyclesReport

Returns a new instance of CyclesReport.

Parameters:

  • root (String)

    absolute analysis root

  • findings (Array<Finding>)

    ranked, largest cycle first

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

    index backend name (e.g. "rubydex")

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

    backend gem version



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/moult/cycles_report.rb', line 37

def initialize(root:, findings:, git_ref: nil, generated_at: nil,
  backend: "rubydex", backend_version: nil, resolved: true, diagnostics: [])
  @root = root
  @findings = findings
  @git_ref = git_ref
  @generated_at = generated_at
  @backend = backend
  @backend_version = backend_version
  @resolved = resolved
  @diagnostics = diagnostics
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def backend
  @backend
end

#backend_versionObject (readonly)

Returns the value of attribute backend_version.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def backend_version
  @backend_version
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def diagnostics
  @diagnostics
end

#findingsObject (readonly)

Returns the value of attribute findings.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def findings
  @findings
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def git_ref
  @git_ref
end

#resolvedObject (readonly)

Returns the value of attribute resolved.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def resolved
  @resolved
end

#rootObject (readonly)

Returns the value of attribute root.



30
31
32
# File 'lib/moult/cycles_report.rb', line 30

def root
  @root
end

Instance Method Details

#summaryHash

Returns aggregate counts across all cycles.

Returns:

  • (Hash)

    aggregate counts across all cycles



50
51
52
53
54
55
56
# File 'lib/moult/cycles_report.rb', line 50

def summary
  {
    cycles: findings.size,
    files: findings.sum { |f| f.files.size },
    largest: findings.map(&:size).max || 0
  }
end

#to_hObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/moult/cycles_report.rb', line 58

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