Class: Edoxen::LinkChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/edoxen/link_checker.rb,
sig/edoxen.rbs

Overview

Walks a directory tree of Meeting and DecisionCollection YAML files and asserts that every cross-document URN link resolves.

Invariants enforced:

* Every Meeting#urn (if set) is unique across the scanned tree.
* Every DecisionCollection#metadata.meeting_urn (if set)
resolves to a Meeting whose urn matches.

Use from CLI / scripts via the public check class method. Returns an array of LinkError records (empty = ok).

All file IO is read-only. No edits to the YAMLs.

Architecture: two passes.

1. `index_pass` walks every file, classifies its top-level shape
 via one of three MECE predicates (`meeting_collection_shape?`,
 `meeting_shape?`, `decision_collection_shape?`), and records
 URN → IndexEntry pairs. Duplicate URNs are reported here.
2. `verify_pass` checks every cross-document link in the indexed
 collections against the indexed meetings.

Adding a new link type is one new field-reading line in index_pass (if the source side needs indexing) plus one iteration in verify_pass. Adding a new top-level shape is one new predicate + one new branch in index_pass.

Defined Under Namespace

Classes: IndexEntry

Constant Summary collapse

LinkError =

Returns:

  • (Object)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ LinkChecker

Returns a new instance of LinkChecker.

Parameters:

  • dir (String)


58
59
60
61
62
# File 'lib/edoxen/link_checker.rb', line 58

def initialize(dir)
  @dir = dir
  @meetings_by_urn = {} # urn → IndexEntry(file, line)
  @collections_by_meeting_urn = {} # meeting_urn → IndexEntry(file, line)
end

Class Method Details

.check(dir) ⇒ Array<LinkError>

Walk dir (recursive scan of *.yaml and *.yml), classify each file, and assert every cross-document URN resolves to a real record.

Parameters:

  • dir (String)

Returns:

  • (Array<LinkError>)

    empty when all links resolve.



54
55
56
# File 'lib/edoxen/link_checker.rb', line 54

def self.check(dir)
  new(dir).check
end

Instance Method Details

#checkArray[LinkError]

Returns:



64
65
66
67
68
69
# File 'lib/edoxen/link_checker.rb', line 64

def check
  errors = []
  index_pass(errors)
  verify_pass(errors)
  errors
end