Class: Ucode::Repo::Writers::IndexesWriter

Inherits:
Object
  • Object
show all
Includes:
AtomicWrites
Defined in:
lib/ucode/repo/writers/indexes_writer.rb

Overview

Writes the three lookup indexes:

output/index/names.json              (cp_id → name)
output/index/labels.json             (cp_id → {name, gc, sc, cc, bc, mir})
output/index/codepoint_to_block.json (cp_id → block_id)

One of the eight per-concern writers split out from AggregateWriter — see Candidate 5 of the 2026-06-29 review.

Instance Method Summary collapse

Methods included from AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Constructor Details

#initialize(output_root:, names:, labels:, cp_to_block:) ⇒ IndexesWriter

Returns a new instance of IndexesWriter.

Parameters:

  • output_root (Pathname)
  • names (Hash{String => String})

    cp_id → name

  • labels (Hash{String => Hash})

    cp_id → label fields

  • cp_to_block (Hash{String => String})

    cp_id → block_id



25
26
27
28
29
30
# File 'lib/ucode/repo/writers/indexes_writer.rb', line 25

def initialize(output_root:, names:, labels:, cp_to_block:)
  @output_root = output_root
  @names = names
  @labels = labels
  @cp_to_block = cp_to_block
end

Instance Method Details

#writeInteger

Returns number of index files written (always 3 when the directory is reachable).

Returns:

  • (Integer)

    number of index files written (always 3 when the directory is reachable)



34
35
36
37
38
39
40
41
42
43
# File 'lib/ucode/repo/writers/indexes_writer.rb', line 34

def write
  count = 0
  count += 1 if write_atomic(Paths.names_index_path(@output_root),
                              to_pretty_json(@names))
  count += 1 if write_atomic(Paths.labels_index_path(@output_root),
                              to_pretty_json(@labels))
  count += 1 if write_atomic(codepoint_to_block_path,
                              to_pretty_json(@cp_to_block))
  count
end