Class: Railsmith::ArchReport

Inherits:
Object
  • Object
show all
Defined in:
lib/railsmith/arch_report.rb

Overview

Formats static-analysis violations for human and machine consumption.

Supports two output formats:

  • as_text — multi-line, human-readable report for local runs.

  • as_json — single JSON object for CI tooling and log aggregation.

Usage:

report = Railsmith::ArchReport.new(violations: violations, checked_files: files, fail_on_arch_violations: true)
puts report.as_text
# or
puts report.as_json

Constant Summary collapse

SEPARATOR =
("=" * 30).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(violations:, checked_files: [], fail_on_arch_violations: false) ⇒ ArchReport

Returns a new instance of ArchReport.

Parameters:

  • violations (Array<ArchChecks::Violation>)
  • checked_files (Array<String>) (defaults to: [])

    paths that were analysed

  • fail_on_arch_violations (Boolean) (defaults to: false)

    when true, text footer reflects CI fail-on mode



25
26
27
28
29
# File 'lib/railsmith/arch_report.rb', line 25

def initialize(violations:, checked_files: [], fail_on_arch_violations: false)
  @violations = Array(violations)
  @checked_files = Array(checked_files)
  @fail_on_arch_violations = fail_on_arch_violations
end

Instance Attribute Details

#checked_filesObject (readonly)

Returns the value of attribute checked_files.



20
21
22
# File 'lib/railsmith/arch_report.rb', line 20

def checked_files
  @checked_files
end

#fail_on_arch_violationsObject (readonly)

Returns the value of attribute fail_on_arch_violations.



20
21
22
# File 'lib/railsmith/arch_report.rb', line 20

def fail_on_arch_violations
  @fail_on_arch_violations
end

#violationsObject (readonly)

Returns the value of attribute violations.



20
21
22
# File 'lib/railsmith/arch_report.rb', line 20

def violations
  @violations
end

Instance Method Details

#as_jsonString

Single JSON object suitable for CI log parsing.

Returns:

  • (String)


56
57
58
# File 'lib/railsmith/arch_report.rb', line 56

def as_json
  JSON.generate(to_h)
end

#as_textString

Multi-line, human-readable text report.

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
# File 'lib/railsmith/arch_report.rb', line 43

def as_text
  lines = ["Railsmith Architecture Check", SEPARATOR, summary_line]
  unless violations.empty?
    lines << ""
    violations.each { |v| lines.concat(violation_lines(v)) }
    lines << ""
  end
  lines << footer_line
  lines.join("\n")
end

#clean?Boolean

Returns true when no violations were found.

Returns:

  • (Boolean)

    true when no violations were found



32
33
34
# File 'lib/railsmith/arch_report.rb', line 32

def clean?
  violations.empty?
end

#to_hHash

Returns:

  • (Hash)


61
62
63
64
65
66
# File 'lib/railsmith/arch_report.rb', line 61

def to_h
  {
    summary: summary_hash.merge(fail_on_arch_violations: fail_on_arch_violations),
    violations: violations.map { |v| violation_to_h(v) }
  }
end

#violation_countInteger

Returns:

  • (Integer)


37
38
39
# File 'lib/railsmith/arch_report.rb', line 37

def violation_count
  violations.size
end