Class: Shadwire::Commands::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/shadwire/commands/update.rb

Overview

Re-applies the registry version of installed components. With no names it updates every installed item. It surfaces local drift (via Differ) before writing so edits are never clobbered silently, then reuses add's overwrite policy, dependency handling, and installed bookkeeping. --yes/--overwrite skip the per-file prompt; --no-deps limits the update to the named items.

Instance Method Summary collapse

Constructor Details

#initialize(root:, names: [], yes: false, overwrite: false, no_deps: false, registry: nil, json: false, ui: UI.new(yes:), runner: Dependencies::DEFAULT_RUNNER) ⇒ Update

Returns a new instance of Update.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shadwire/commands/update.rb', line 13

def initialize(root:, names: [], yes: false, overwrite: false, no_deps: false,
               registry: nil, json: false, ui: UI.new(yes:), runner: Dependencies::DEFAULT_RUNNER)
  @root = root.to_s
  @names = names
  @yes = yes
  @overwrite = overwrite
  @no_deps = no_deps
  @registry_override = registry
  @json = json
  @ui = ui
  @runner = runner
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shadwire/commands/update.rb', line 26

def call
  project = Project.new(@root)
  project.raise_unless_rails!

  config = Config.load(@root)
  client = RegistryClient.new(@registry_override || config.registry)
  targets = resolve_targets(config)

  items = resolve_items(targets, client)
  files = items.flat_map { |item| item.fetch("files") }

  diffs = compute_diffs(files) # read local drift before any overwrite
  report = install_files(files)

  deps = Dependencies.new(project, runner: @runner)
  dep_confirm = ->(desc) { @ui.confirm?(desc) }
  gems = deps.ensure_gems(union(items, "gems"), yes: @yes, confirm: dep_confirm)
  pins = deps.ensure_importmap_pins(union(items, "importmap"), yes: @yes, confirm: dep_confirm)

  record_installed(config, client, targets, items)
  config.save

  result = { updated: targets, report:, gems:, pins:, diffs: }
  emit(result)
  Dependencies.raise_on_failure!(gems, pins)

  result
end