Class: Shadwire::Installer
- Inherits:
-
Object
- Object
- Shadwire::Installer
- Defined in:
- lib/shadwire/installer.rb
Overview
Writes published registry file entries into a consuming Rails app, applying the same safety checks bin/sync_registry enforces. It is non-interactive: the overwrite policy and an optional confirm callable are injected so that commands own the UI and tests stay deterministic.
A file entry is a Hash of the published shape:
{ "target" => "app/.../x.rb", "type" => "component", "content" => "..." }
Instance Method Summary collapse
-
#initialize(root, overwrite: :prompt, confirm: nil) ⇒ Installer
constructor
A new instance of Installer.
-
#install(files) ⇒ Hash
Validates all targets (fail-fast), then writes.
Constructor Details
Instance Method Details
#install(files) ⇒ Hash
Validates all targets (fail-fast), then writes.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shadwire/installer.rb', line 28 def install(files) planned = validate(files) written = [] skipped = [] planned.each do |target, content| path = @root.join(target) if path.exist? && !overwrite?(target) skipped << target next end FileUtils.mkdir_p(path.dirname) path.write(content) written << target end { written:, skipped: } end |