Class: Ucode::Repo::AggregateWriter
- Inherits:
-
Object
- Object
- Ucode::Repo::AggregateWriter
- Defined in:
- lib/ucode/repo/aggregate_writer.rb
Overview
Writes every aggregate JSON file under output/:
output/planes/<n>.json
output/blocks/<ID>.json
output/blocks/index.json
output/scripts/<code>.json
output/index/names.json
output/index/labels.json
output/index/codepoint_to_block.json
output/relationships/*.json
output/enums.json
output/named_sequences/<slug>.json
output/manifest.json
Single pass: callers feed one CodePoint at a time via #add,
which folds into the streaming accumulators. #flush then
composes eight per-concern writer classes (one per output kind)
and runs them in order. Adding a new aggregate = adding one
writer class + one line here. See Candidate 5 of the 2026-06-29
architecture review.
MECE:
- paths: `Repo::Paths`
- atomic writes: `Repo::AtomicWrites`
- stream aggregation: this class (the `#add` half)
- per-concern writers: `Repo::Writers::*`
- serialization: lutaml-model `to_yaml_hash` / `to_json`
Instance Attribute Summary collapse
-
#codepoint_count ⇒ Object
readonly
Returns the value of attribute codepoint_count.
Instance Method Summary collapse
-
#add(cp) ⇒ void
Fold one CodePoint into the stream accumulators.
-
#flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) ⇒ Integer
Compose the eight per-concern writers, run them in order, and return the total number of files written.
-
#initialize(output_root) ⇒ AggregateWriter
constructor
A new instance of AggregateWriter.
- #writers(ucd_version, indices, property_aliases, property_value_aliases, named_sequences, glyph_count) ⇒ Object
Constructor Details
#initialize(output_root) ⇒ AggregateWriter
Returns a new instance of AggregateWriter.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 45 def initialize(output_root) @output_root = Pathname.new(output_root) @block_codepoint_ids = Hash.new { |h, k| h[k] = [] } @block_ages = Hash.new { |h, k| h[k] = nil } @script_codepoint_ids = Hash.new { |h, k| h[k] = [] } @names_index = {} @labels_index = {} @cp_to_block = {} @codepoint_count = 0 end |
Instance Attribute Details
#codepoint_count ⇒ Object (readonly)
Returns the value of attribute codepoint_count.
56 57 58 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 56 def codepoint_count @codepoint_count end |
Instance Method Details
#add(cp) ⇒ void
This method returns an undefined value.
Fold one CodePoint into the stream accumulators. No-ops if the cp has no block_id (it has no home in the output tree).
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 62 def add(cp) return if cp.block_id.nil? @block_codepoint_ids[cp.block_id] << cp.id track_block_age(cp) if cp.script_code @script_codepoint_ids[cp.script_code] << cp.id end if cp.name && !cp.name.empty? @names_index[cp.id] = cp.name end @labels_index[cp.id] = build_label(cp) @cp_to_block[cp.id] = cp.block_id @codepoint_count += 1 end |
#flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) ⇒ Integer
Compose the eight per-concern writers, run them in order, and return the total number of files written.
88 89 90 91 92 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 88 def flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) writers(ucd_version, indices, property_aliases, property_value_aliases, named_sequences, glyph_count).sum(&:write) end |
#writers(ucd_version, indices, property_aliases, property_value_aliases, named_sequences, glyph_count) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 95 def writers(ucd_version, indices, property_aliases, property_value_aliases, named_sequences, glyph_count) [ Writers::PlanesWriter.new(output_root: @output_root, blocks: indices.blocks), Writers::BlocksWriter.new(output_root: @output_root, blocks: indices.blocks, block_codepoint_ids: @block_codepoint_ids, block_ages: @block_ages), Writers::ScriptsWriter.new(output_root: @output_root, scripts: indices.scripts, script_codepoint_ids: @script_codepoint_ids), Writers::IndexesWriter.new(output_root: @output_root, names: @names_index, labels: @labels_index, cp_to_block: @cp_to_block), Writers::RelationshipsWriter.new(output_root: @output_root, indices: indices), Writers::EnumsWriter.new(output_root: @output_root, property_aliases: property_aliases, property_value_aliases: property_value_aliases), Writers::NamedSequencesWriter.new(output_root: @output_root, named_sequences: named_sequences), Writers::ManifestWriter.new(output_root: @output_root, ucd_version: ucd_version, codepoint_count: @codepoint_count, glyph_count: glyph_count), ] end |