Class: Textus::Manifest::Entry::Publish::ToPaths

Inherits:
Mode
  • Object
show all
Defined in:
lib/textus/manifest/entry/publish/to_paths.rb

Overview

publish_to: copy the entry’s one stored file to each fixed repo path. The default behaviour of any entry that declares ‘publish_to:`.

Instance Attribute Summary

Attributes inherited from Mode

#entry

Instance Method Summary collapse

Methods inherited from Mode

#initialize, #validate!

Constructor Details

This class inherits a constructor from Textus::Manifest::Entry::Publish::Mode

Instance Method Details

#publish(pctx, prefix: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/textus/manifest/entry/publish/to_paths.rb', line 8

def publish(pctx, prefix: nil) # rubocop:disable Lint/UnusedMethodArgument
  targets = Array(entry.publish_to)
  return nil if targets.empty?

  source_path = pctx.manifest.resolver.resolve(entry.key).path
  envelope = pctx.reader.call(entry.key)

  targets.each do |rel|
    target_abs = File.join(pctx.repo_root, rel)
    Textus::Ports::Publisher.publish(source: source_path, target: target_abs, store_root: pctx.root)
    pctx.emit(:file_published, key: entry.key, envelope: envelope, source: source_path, target: target_abs)
  end

  { kind: :built, value: { "key" => entry.key, "path" => source_path, "published_to" => targets } }
end