Class: LinkRegistry
- Inherits:
-
Object
- Object
- LinkRegistry
- 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
-
#collisions ⇒ Object
readonly
Returns the value of attribute collisions.
Instance Method Summary collapse
- #find_by_id(id) ⇒ Object
- #find_by_source(source_path) ⇒ Object
-
#initialize ⇒ LinkRegistry
constructor
A new instance of LinkRegistry.
-
#register(doc) ⇒ Object
Each registered document is expected to already carry an output_rel_path (its generated page, relative to the build root).
Constructor Details
#initialize ⇒ LinkRegistry
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
#collisions ⇒ Object (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.(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) key = doc.id.to_s.downcase if @by_id.key?(key) && !@by_id[key].equal?(doc) @collisions << key else @by_id[key] = doc end return unless doc.respond_to?(:path) && doc.path @by_source[File.(doc.path)] = doc end |