Class: Railsmith::ArchReport
- Inherits:
-
Object
- Object
- Railsmith::ArchReport
- 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
-
#checked_files ⇒ Object
readonly
Returns the value of attribute checked_files.
-
#fail_on_arch_violations ⇒ Object
readonly
Returns the value of attribute fail_on_arch_violations.
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#as_json ⇒ String
Single JSON object suitable for CI log parsing.
-
#as_text ⇒ String
Multi-line, human-readable text report.
-
#clean? ⇒ Boolean
True when no violations were found.
-
#initialize(violations:, checked_files: [], fail_on_arch_violations: false) ⇒ ArchReport
constructor
A new instance of ArchReport.
- #to_h ⇒ Hash
- #violation_count ⇒ Integer
Constructor Details
#initialize(violations:, checked_files: [], fail_on_arch_violations: false) ⇒ ArchReport
Returns a new instance of ArchReport.
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_files ⇒ Object (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_violations ⇒ Object (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 |
#violations ⇒ Object (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_json ⇒ String
Single JSON object suitable for CI log parsing.
56 57 58 |
# File 'lib/railsmith/arch_report.rb', line 56 def as_json JSON.generate(to_h) end |
#as_text ⇒ String
Multi-line, human-readable text report.
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 << lines.join("\n") end |
#clean? ⇒ Boolean
Returns true when no violations were found.
32 33 34 |
# File 'lib/railsmith/arch_report.rb', line 32 def clean? violations.empty? end |
#to_h ⇒ 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_count ⇒ Integer
37 38 39 |
# File 'lib/railsmith/arch_report.rb', line 37 def violation_count violations.size end |