Class: Ucode::Repo::Writers::BlocksWriter

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

Overview

Writes output/blocks/<ID>.json for every block plus output/blocks/index.json as a summary.

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:, blocks:, block_codepoint_ids:, block_ages:) ⇒ BlocksWriter

Returns a new instance of BlocksWriter.

Parameters:

  • output_root (Pathname)
  • blocks (Array<Ucode::Models::Block>)
  • block_codepoint_ids (Hash{String => Array<String>})

    block_id → sorted cp_id list, accumulated during the streaming pass

  • block_ages (Hash{String => String})

    block_id → earliest DerivedAge string; nil entries get written as nil



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

def initialize(output_root:, blocks:, block_codepoint_ids:, block_ages:)
  @output_root = output_root
  @blocks = blocks
  @block_codepoint_ids = block_codepoint_ids
  @block_ages = block_ages
end

Instance Method Details

#writeInteger

Returns number of files written (one per block plus one for the index).

Returns:

  • (Integer)

    number of files written (one per block plus one for the index)



33
34
35
36
37
38
39
40
# File 'lib/ucode/repo/writers/blocks_writer.rb', line 33

def write
  count = @blocks.sum do |block|
    block.age = @block_ages[block.id]
    path = Paths.(@output_root, block.id)
    write_atomic(path, block_payload(block)) ? 1 : 0
  end
  count + write_blocks_index
end