Class: Suma::LinkValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/link_validation.rb

Overview

Deep module behind the EXPRESS cross-reference validation pipeline.

Interface: paths in, Result out. The CLI is a thin adapter that constructs this object and prints the result.

Owns: loading the schemas manifest, discovering + reading .adoc and .exp files, extracting express cross-reference links, loading parsed schemas into a SchemaIndex, delegating to LinkValidator for the actual resolution, and writing the summary file.

Does not own: presentation (use LinkValidation.generate_summary), command-line argument parsing (the CLI adapter does that), or the link-resolution rules themselves (that is +LinkValidator+'s job).

Defined Under Namespace

Classes: NullProgress, Result

Constant Summary collapse

/<<express:([^,>]+)(?:,[^>]+)?>>/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schemas_file:, documents_path:, output_file:, progress: NullProgress.new, logger: Utils) ⇒ LinkValidation

Returns a new instance of LinkValidation.



26
27
28
29
30
31
32
33
# File 'lib/suma/link_validation.rb', line 26

def initialize(schemas_file:, documents_path:, output_file:,
               progress: NullProgress.new, logger: Utils)
  @schemas_file = Pathname.new(schemas_file).expand_path
  @documents_path = Pathname.new(documents_path).expand_path
  @output_file = output_file && Pathname.new(output_file).expand_path
  @progress = progress
  @logger = logger
end

Instance Attribute Details

#documents_pathObject (readonly)

Returns the value of attribute documents_path.



23
24
25
# File 'lib/suma/link_validation.rb', line 23

def documents_path
  @documents_path
end

#loggerObject (readonly)

Returns the value of attribute logger.



23
24
25
# File 'lib/suma/link_validation.rb', line 23

def logger
  @logger
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



23
24
25
# File 'lib/suma/link_validation.rb', line 23

def output_file
  @output_file
end

#progressObject (readonly)

Returns the value of attribute progress.



23
24
25
# File 'lib/suma/link_validation.rb', line 23

def progress
  @progress
end

#schemas_fileObject (readonly)

Returns the value of attribute schemas_file.



23
24
25
# File 'lib/suma/link_validation.rb', line 23

def schemas_file
  @schemas_file
end

Class Method Details

.generate_summary(result) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/suma/link_validation.rb', line 51

def self.generate_summary(result)
  lines = []
  lines << "Validation complete. Checked #{result.total_links} links."
  if result.success?
    lines << "✅ All links resolved successfully!"
  else
    lines << "❌ Found #{result.unresolved.size} unresolved links:"
    result.unresolved.each { |issue| lines << format_issue(issue) }
  end
  lines.join("\n")
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/suma/link_validation.rb', line 35

def call
  config = load_schemas_config
  exp_files = collect_schema_paths(config)
  adoc_files = find_adoc_files
  links_by_file = extract_links(adoc_files + exp_files)
  unresolved = validate_links(config, links_by_file)
  result = Result.new(
    adoc_count: adoc_files.size,
    exp_count: exp_files.size,
    total_links: links_by_file.values.sum(&:size),
    unresolved: unresolved,
  )
  write_summary(result) if output_file
  result
end