Class: Ucode::Repo::Writers::NamedSequencesWriter

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

Overview

Writes one file per named sequence under output/named_sequences/<slug>.json. Empty input writes nothing.

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:, named_sequences:) ⇒ NamedSequencesWriter

Returns a new instance of NamedSequencesWriter.

Parameters:



19
20
21
22
# File 'lib/ucode/repo/writers/named_sequences_writer.rb', line 19

def initialize(output_root:, named_sequences:)
  @output_root = output_root
  @named_sequences = named_sequences
end

Instance Method Details

#writeInteger

Returns number of named-sequence files written.

Returns:

  • (Integer)

    number of named-sequence files written



25
26
27
28
29
30
31
32
33
# File 'lib/ucode/repo/writers/named_sequences_writer.rb', line 25

def write
  return 0 if @named_sequences.nil? || @named_sequences.empty?

  dir = Pathname(@output_root).join("named_sequences")
  @named_sequences.sum do |ns|
    path = dir.join("#{slug_for(ns)}.json")
    write_atomic(path, ns.to_json(pretty: true)) ? 1 : 0
  end
end