Module: Textus::Builder::Pipeline

Defined in:
lib/textus/builder/pipeline.rb

Defined Under Namespace

Classes: Deps

Class Method Summary collapse

Class Method Details

.renderersObject



34
35
36
37
38
39
40
41
# File 'lib/textus/builder/pipeline.rb', line 34

def self.renderers
  @renderers ||= {
    "markdown" => Renderer::Markdown,
    "text" => Renderer::Text,
    "json" => Renderer::Json,
    "yaml" => Renderer::Yaml,
  }
end

.run(mentry:, deps:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/textus/builder/pipeline.rb', line 43

def self.run(mentry:, deps:)
  # 1. Load sources + project + reduce. Only projection-derived entries are
  # buildable in-process; External entries are generated out-of-band and are
  # filtered out upstream (Derived#publish_via), so reaching here with a
  # non-projection source is a wiring bug — fail loudly rather than emit an
  # empty payload (and never re-stamp the volatile generated_at, ADR 0070).
  unless mentry.is_a?(Textus::Manifest::Entry::Derived) && mentry.projection?
    raise UsageError.new(
      "builder: '#{mentry.key}' is not a projection-derived entry; only projections are buildable",
    )
  end

  data =
    Textus::Projection.new(
      reader: deps.reader,
      spec: mentry.source.to_h.transform_keys(&:to_s),
      lister: deps.lister,
      rpc: deps.rpc,
      transform_context: deps.transform_context,
    ).run
  data = data.merge("boot" => deps.inject_boot.call) if mentry.inject_boot && deps.inject_boot

  # 2. Render
  klass = renderers[mentry.format] or
    raise UsageError.new("builder: unsupported format #{mentry.format.inspect} for '#{mentry.key}'")
  bytes = klass.new(template_loader: deps.template_loader).call(mentry: mentry, data: data)

  # 3. Write (idempotent: skip if only generated_at would differ)
  target_path = Key::Path.resolve(deps.manifest.data, mentry)
  FileUtils.mkdir_p(File.dirname(target_path))
  write_if_changed(target_path, bytes, mentry.format)

  target_path
end

.write_if_changed(target_path, bytes, _format) ⇒ Object

Built artifacts are content-addressed (no volatile timestamp, ADR 0070), so identity is plain byte-equality: skip the write when nothing changed. ‘format` is retained for signature stability across renderers.



81
82
83
84
85
# File 'lib/textus/builder/pipeline.rb', line 81

def self.write_if_changed(target_path, bytes, _format)
  return if File.exist?(target_path) && File.binread(target_path) == bytes

  File.binwrite(target_path, bytes)
end