Module: Coradoc::Mirror::ReverseBuilder

Defined in:
lib/coradoc/mirror/reverse_builder.rb,
lib/coradoc/mirror/reverse_builder/toc.rb,
lib/coradoc/mirror/reverse_builder/base.rb,
lib/coradoc/mirror/reverse_builder/text.rb,
lib/coradoc/mirror/reverse_builder/image.rb,
lib/coradoc/mirror/reverse_builder/table.rb,
lib/coradoc/mirror/reverse_builder/verse.rb,
lib/coradoc/mirror/reverse_builder/figure.rb,
lib/coradoc/mirror/reverse_builder/header.rb,
lib/coradoc/mirror/reverse_builder/caption.rb,
lib/coradoc/mirror/reverse_builder/example.rb,
lib/coradoc/mirror/reverse_builder/include.rb,
lib/coradoc/mirror/reverse_builder/section.rb,
lib/coradoc/mirror/reverse_builder/sidebar.rb,
lib/coradoc/mirror/reverse_builder/abstract.rb,
lib/coradoc/mirror/reverse_builder/document.rb,
lib/coradoc/mirror/reverse_builder/preamble.rb,
lib/coradoc/mirror/reverse_builder/sections.rb,
lib/coradoc/mirror/reverse_builder/footnotes.rb,
lib/coradoc/mirror/reverse_builder/list_item.rb,
lib/coradoc/mirror/reverse_builder/paragraph.rb,
lib/coradoc/mirror/reverse_builder/partintro.rb,
lib/coradoc/mirror/reverse_builder/table_row.rb,
lib/coradoc/mirror/reverse_builder/toc_entry.rb,
lib/coradoc/mirror/reverse_builder/admonition.rb,
lib/coradoc/mirror/reverse_builder/blockquote.rb,
lib/coradoc/mirror/reverse_builder/code_block.rb,
lib/coradoc/mirror/reverse_builder/hard_break.rb,
lib/coradoc/mirror/reverse_builder/open_block.rb,
lib/coradoc/mirror/reverse_builder/pass_block.rb,
lib/coradoc/mirror/reverse_builder/raw_inline.rb,
lib/coradoc/mirror/reverse_builder/soft_break.rb,
lib/coradoc/mirror/reverse_builder/stem_block.rb,
lib/coradoc/mirror/reverse_builder/table_body.rb,
lib/coradoc/mirror/reverse_builder/table_cell.rb,
lib/coradoc/mirror/reverse_builder/table_head.rb,
lib/coradoc/mirror/reverse_builder/bullet_list.rb,
lib/coradoc/mirror/reverse_builder/frontmatter.rb,
lib/coradoc/mirror/reverse_builder/inline_text.rb,
lib/coradoc/mirror/reverse_builder/biblio_entry.rb,
lib/coradoc/mirror/reverse_builder/bibliography.rb,
lib/coradoc/mirror/reverse_builder/ordered_list.rb,
lib/coradoc/mirror/reverse_builder/generic_block.rb,
lib/coradoc/mirror/reverse_builder/literal_block.rb,
lib/coradoc/mirror/reverse_builder/footnote_entry.rb,
lib/coradoc/mirror/reverse_builder/definition_list.rb,
lib/coradoc/mirror/reverse_builder/footnote_marker.rb,
lib/coradoc/mirror/reverse_builder/horizontal_rule.rb

Overview

OCP-compliant registry for Mirror node → CoreModel transformation.

Single source of truth: the TYPE_TO_FILE table below maps every Mirror wire type string (and its aliases) to the file that implements its builder. Two things derive from this one table:

1. autoload declarations — one per unique file, so builders
 load lazily on first lookup (no 47-file eager load at boot).
2. lookup() — type → file → const_get, which triggers autoload.

Adding a new built-in builder is purely additive:

1. Add `'<wire_type>' => '<file_basename>'` to TYPE_TO_FILE.
2. Create `reverse_builder/<file_basename>.rb` defining
 `class <CamelizedName> < Base; def build(node); ...; end; end`.

No edits to this file beyond the table — autoload and lookup adapt automatically. Mirror-level mark dispatch lives in MarkReverseBuilder (mark_reverse_builder.rb).

Third-party / runtime builders can still register via ReverseBuilder.register(type, klass); they take precedence over built-in autoload entries.

Defined Under Namespace

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

Constant Summary collapse

TYPE_TO_FILE =

Wire type string → file basename under reverse_builder/. Aliases (e.g. 'clause' and 'annex' both route to section) are expressed by mapping multiple type strings to the same file.

{
  'doc' => 'document',
  'section' => 'section',
  'clause' => 'section',
  'annex' => 'section',
  'content_section' => 'section',
  'abstract' => 'section',
  'foreword' => 'section',
  'introduction' => 'section',
  'acknowledgements' => 'section',
  'terms' => 'section',
  'definitions' => 'section',
  'references' => 'section',
  'sections' => 'sections',
  'preface' => 'preamble',
  'floating_title' => 'header',
  'heading' => 'header',
  'paragraph' => 'paragraph',
  'sourcecode' => 'code_block',
  'literal' => 'literal_block',
  'pass' => 'pass_block',
  'stem' => 'stem_block',
  'quote' => 'blockquote',
  'example' => 'example',
  'sidebar' => 'sidebar',
  'abstract_block' => 'abstract',
  'partintro_block' => 'partintro',
  'open_block' => 'open_block',
  'verse' => 'verse',
  'horizontal_rule' => 'horizontal_rule',
  'thematic_break' => 'horizontal_rule',
  'soft_break' => 'soft_break',
  'hard_break' => 'hard_break',
  'admonition' => 'admonition',
  'bullet_list' => 'bullet_list',
  'ordered_list' => 'ordered_list',
  'list_item' => 'list_item',
  'dl' => 'definition_list',
  'dt' => 'inline_text',
  'dd' => 'inline_text',
  'image' => 'image',
  'figure' => 'figure',
  'caption' => 'caption',
  'include' => 'include',
  'table' => 'table',
  'table_head' => 'table_head',
  'table_body' => 'table_body',
  'table_row' => 'table_row',
  'table_cell' => 'table_cell',
  'bibliography' => 'bibliography',
  'biblio_entry' => 'biblio_entry',
  'footnotes' => 'footnotes',
  'footnote_entry' => 'footnote_entry',
  'footnote_marker' => 'footnote_marker',
  'toc' => 'toc',
  'toc_entry' => 'toc_entry',
  'text' => 'text',
  'raw_inline' => 'raw_inline',
  'frontmatter' => 'frontmatter',
  'generic_block' => 'generic_block'
}.freeze
FILE_TO_CLASS =

File basename → Ruby constant name. Derived from the file name using the project-wide snake_case → CamelCase convention (every existing builder follows it). Declared once here so adding a builder that follows convention requires no extra wiring.

TYPE_TO_FILE.each_value.each_with_object({}) do |file, acc|
  next if acc.key?(file)

  acc[file] = file.split('_').map(&:capitalize).join
end.freeze
REGISTRY =

Runtime registrations from third-party / external builders. Takes precedence over built-in autoload entries so external code can override built-in behaviour (e.g. a custom Paragraph). Not frozen: register() writes here at runtime.

{}

Class Method Summary collapse

Class Method Details

.lookup(type) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/coradoc/mirror/reverse_builder.rb', line 133

def lookup(type)
  return REGISTRY[type] if REGISTRY.key?(type)

  file = TYPE_TO_FILE[type]
  return nil unless file

  const_get(FILE_TO_CLASS[file])
end

.register(type, builder_class) ⇒ Object



120
121
122
# File 'lib/coradoc/mirror/reverse_builder.rb', line 120

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

.registered_typesObject



142
143
144
# File 'lib/coradoc/mirror/reverse_builder.rb', line 142

def registered_types
  (REGISTRY.keys + TYPE_TO_FILE.keys).uniq
end

.registers(*types) ⇒ Object

DSL for subclasses to self-register at load time. Kept for backward compatibility with the existing OCP test pattern that creates synthetic builders via Class.new(Base) { registers(...) }. Built-in builders no longer call this — their dispatch is derived from TYPE_TO_FILE.



129
130
131
# File 'lib/coradoc/mirror/reverse_builder.rb', line 129

def registers(*types)
  types.each { |t| register(t, self) }
end