Module: Textus::Infra::Publisher

Defined in:
lib/textus/infra/publisher.rb

Overview

Publishes built artifacts from the store to repo-relative consumer paths. Publish = copy + sentinel. The in-store file is already the consumer-shaped artifact; no parsing or stripping.

Sentinel I/O is delegated to Store::Sentinel. Sentinels live under ‘<store_root>/sentinels/` and mirror the target’s repo-relative layout so consumer directories aren’t polluted with ‘.textus-managed.json` siblings.

Class Method Summary collapse

Class Method Details

.cleanup_legacy_sentinel(target) ⇒ Object



34
35
36
# File 'lib/textus/infra/publisher.rb', line 34

def self.cleanup_legacy_sentinel(target)
  FileUtils.rm_f(Store::Sentinel.legacy_path(target))
end

.managed?(target, store_root) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/textus/infra/publisher.rb', line 29

def self.managed?(target, store_root)
  File.exist?(Store::Sentinel.sentinel_path(target, store_root)) ||
    File.exist?(Store::Sentinel.legacy_path(target))
end

.publish(source:, target:, store_root:) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/textus/infra/publisher.rb', line 13

def self.publish(source:, target:, store_root:)
  FileUtils.mkdir_p(File.dirname(target))
  refuse_if_unmanaged(target, store_root)
  File.delete(target) if File.symlink?(target)
  FileUtils.cp(source, target)
  Store::Sentinel.write!(target: target, source: source, store_root: store_root)
  cleanup_legacy_sentinel(target)
end

.refuse_if_unmanaged(target, store_root) ⇒ Object

Raises:



22
23
24
25
26
27
# File 'lib/textus/infra/publisher.rb', line 22

def self.refuse_if_unmanaged(target, store_root)
  return unless File.exist?(target) || File.symlink?(target)
  return if managed?(target, store_root)

  raise PublishError.new("refusing to clobber unmanaged file at #{target}", target: target)
end