Class: Textus::Write::Publish

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/write/publish.rb

Overview

Single-pass publish use case: dispatches polymorphically to each entry’s ‘publish_via` method. Derived entries materialize their body via Materializer; Nested entries fan out via publish_each; Leaf and Intake entries copy their stored body to publish_to targets. The Publish layer owns wiring (context, accumulation) but not per-kind logic.

Return shape: { “protocol”, “built”, “published_leaves” }

Instance Method Summary collapse

Constructor Details

#initialize(container:, call:) ⇒ Publish

Returns a new instance of Publish.



12
13
14
15
16
# File 'lib/textus/write/publish.rb', line 12

def initialize(container:, call:)
  @container = container
  @call      = call
  @manifest  = container.manifest
end

Instance Method Details

#call(prefix: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/textus/write/publish.rb', line 18

def call(prefix: nil)
  built  = []
  leaves = []
  context = build_context

  @manifest.data.entries.each do |mentry|
    next if prefix && !entry_matches_prefix?(mentry, prefix)

    result = mentry.publish_via(context, prefix: prefix)
    next if result.nil?

    case result[:kind]
    when :built  then built << result[:value]
    when :leaves then leaves.concat(result[:value])
    end
  end

  { "protocol" => Textus::PROTOCOL, "built" => built, "published_leaves" => leaves }
end