Module: Coradoc::Mirror::ReverseBuilder

Defined in:
lib/coradoc/mirror/reverse_builder.rb

Overview

OCP-compliant registry for Mirror node -> CoreModel transformation.

Adding support for a new Mirror node type is purely additive:

module ReverseBuilder
  class Figure < Base
    registers 'figure'

    def build(node)
      CoreModel::Image.new(src: node.src, ...)
    end
  end
end

No edits to MirrorToCoreModel or any other existing class. The registry is the single source of truth for “which type string maps to which builder” (MECE).

This file is the autoload target for the ReverseBuilder constant (see coradoc/mirror.rb). All built-in Builder subclasses live here so their ‘registers` calls run at load time and the REGISTRY is full before any caller references it. Mirror-level mark dispatch lives in MarkReverseBuilder (mark_reverse_builder.rb).

Defined Under Namespace

Modules: FrontmatterTreeToHash Classes: Admonition, Base, BiblioEntry, Bibliography, Blockquote, BulletList, Caption, CodeBlock, DefinitionList, Document, Example, Figure, FootnoteEntry, FootnoteMarker, Footnotes, Frontmatter, GenericBlock, Header, HorizontalRule, Image, InlineText, ListItem, OpenBlock, OrderedList, Paragraph, Preamble, Section, Sections, Sidebar, SoftBreak, Table, TableBody, TableCell, TableHead, TableRow, Text, Toc, TocEntry, Verse

Constant Summary collapse

REGISTRY =
{}

Class Method Summary collapse

Class Method Details

.lookup(type) ⇒ Object



37
38
39
# File 'lib/coradoc/mirror/reverse_builder.rb', line 37

def lookup(type)
  REGISTRY[type]
end

.register(type, builder_class) ⇒ Object



33
34
35
# File 'lib/coradoc/mirror/reverse_builder.rb', line 33

def register(type, builder_class)
  REGISTRY[type] = builder_class
end

.registered_typesObject



41
42
43
# File 'lib/coradoc/mirror/reverse_builder.rb', line 41

def registered_types
  REGISTRY.keys
end