Class: LinkRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/almirah/link_registry.rb

Overview

Project-wide registry of managed documents, used to resolve cross-document links (ADR-186) to their generated output pages. Documents are indexed by their id / filename stem (case-insensitive, folder-independent) and, when they originate from a source file, by their absolute source path (for native Markdown relative links).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLinkRegistry

Returns a new instance of LinkRegistry.



11
12
13
14
15
# File 'lib/almirah/link_registry.rb', line 11

def initialize
  @by_id = {}
  @by_source = {}
  @collisions = []
end

Instance Attribute Details

#collisionsObject (readonly)

Returns the value of attribute collisions.



9
10
11
# File 'lib/almirah/link_registry.rb', line 9

def collisions
  @collisions
end

Instance Method Details

#find_by_id(id) ⇒ Object



31
32
33
# File 'lib/almirah/link_registry.rb', line 31

def find_by_id(id)
  @by_id[id.to_s.downcase]
end

#find_by_source(source_path) ⇒ Object



35
36
37
# File 'lib/almirah/link_registry.rb', line 35

def find_by_source(source_path)
  @by_source[File.expand_path(source_path)]
end

#register(doc) ⇒ Object

Each registered document is expected to already carry an output_rel_path (its generated page, relative to the build root).



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/almirah/link_registry.rb', line 19

def register(doc)
  register_id(doc.id.to_s.downcase, doc)
  return unless doc.respond_to?(:path) && doc.path

  # Also index by the filename stem so a document resolves by filename, not
  # only by id (SRS-090). For specs/protocols the stem equals the id; for
  # decision records the id is the truncated <letters>-<digits> prefix, so the
  # full stem (e.g. "adr-170-introduce-decision-records") is a distinct alias.
  register_id(File.basename(doc.path, '.*').downcase, doc)
  @by_source[File.expand_path(doc.path)] = doc
end