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

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

Constant Summary collapse

REGISTRY =

Not frozen: subclasses call ‘register` from their class body at load time, and `registers` may fire late via autoload. Freezing here breaks the first mirror-to-core round-trip after load.

{}

Class Method Summary collapse

Class Method Details

.lookup(type) ⇒ Object



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

def lookup(type)
  REGISTRY[type]
end

.register(type, builder_class) ⇒ Object



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

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

.registered_typesObject



44
45
46
# File 'lib/coradoc/mirror/reverse_builder.rb', line 44

def registered_types
  REGISTRY.keys
end