Class: Homebrew::Bundle::Extension Abstract Private

Inherits:
PackageType show all
Extended by:
T::Helpers
Defined in:
bundle/extensions/extension.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Direct Known Subclasses

Cargo, Flatpak, Go, Krew, MacAppStore, Npm, Uv, VscodeExtension, Winget

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PackageType

check_label, #checkable_entries, #exit_early_check, #find_actionable, #format_checkable, #full_check, type

Class Method Details

.add_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


127
128
129
# File 'bundle/extensions/extension.rb', line 127

def self.add_supported?
  true
end

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method is abstract.

Returns:



22
# File 'bundle/extensions/extension.rb', line 22

def self.banner_name; end

.check(entries, exit_on_first_error: false, no_upgrade: false, verbose: false) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • entries (Array<Dsl::Entry>)
  • exit_on_first_error (Boolean) (defaults to: false)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)

Returns:



226
227
228
# File 'bundle/extensions/extension.rb', line 226

def self.check(entries, exit_on_first_error: false, no_upgrade: false, verbose: false)
  new.find_actionable(entries, exit_on_first_error:, no_upgrade:, verbose:)
end

.cleanup!(items) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



255
256
257
258
259
260
261
262
263
264
265
# File 'bundle/extensions/extension.rb', line 255

def self.cleanup!(items)
  executable = package_manager_executable
  return if executable.nil?

  with_env(package_manager_env(executable)) do
    items.each do |name|
      uninstall_package!(name, executable:)
    end
  end
  puts "Uninstalled #{items.size} #{banner_name}#{"s" if items.size != 1}"
end

.cleanup_disable_descriptionString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



112
113
114
# File 'bundle/extensions/extension.rb', line 112

def self.cleanup_disable_description
  "`cleanup` without #{banner_name}."
end

.cleanup_disable_envSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



102
103
104
# File 'bundle/extensions/extension.rb', line 102

def self.cleanup_disable_env
  :"bundle_cleanup_no_#{type}"
end

.cleanup_headingString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



162
163
164
# File 'bundle/extensions/extension.rb', line 162

def self.cleanup_heading
  nil
end

.cleanup_item_name(item) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



245
246
247
# File 'bundle/extensions/extension.rb', line 245

def self.cleanup_item_name(item)
  item
end

.cleanup_items(entries) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



231
232
233
234
235
236
237
238
239
240
241
242
# File 'bundle/extensions/extension.rb', line 231

def self.cleanup_items(entries)
  return [].freeze unless package_manager_installed?

  kept_packages = entries.filter_map do |entry|
    entry.name if entry.type == type
  end

  return [].freeze if kept_packages.empty?

  installed_names = packages.map { |pkg| dump_name(pkg) }
  installed_names - kept_packages
end

.cleanup_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


167
168
169
# File 'bundle/extensions/extension.rb', line 167

def self.cleanup_supported?
  !cleanup_heading.nil?
end

.disable_predicate_methodSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



122
123
124
# File 'bundle/extensions/extension.rb', line 122

def self.disable_predicate_method
  :"no_#{type}?"
end

.dumpString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



206
207
208
# File 'bundle/extensions/extension.rb', line 206

def self.dump
  packages.map { |package| dump_entry(package) }.join("\n")
end

.dump_disable_descriptionString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



92
93
94
# File 'bundle/extensions/extension.rb', line 92

def self.dump_disable_description
  "`dump` without #{banner_name}."
end

.dump_disable_envSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



97
98
99
# File 'bundle/extensions/extension.rb', line 97

def self.dump_disable_env
  :"bundle_dump_no_#{type}"
end

.dump_disable_predicate_methodSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



117
118
119
# File 'bundle/extensions/extension.rb', line 117

def self.dump_disable_predicate_method
  disable_predicate_method
end

.dump_disable_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


107
108
109
# File 'bundle/extensions/extension.rb', line 107

def self.dump_disable_supported?
  true
end

.dump_entry(package) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



181
182
183
184
185
186
187
188
# File 'bundle/extensions/extension.rb', line 181

def self.dump_entry(package)
  line = "#{type} #{quote(dump_name(package))}"
  with = dump_with(package)
  return line if with.blank?

  formatted_with = with.map { |requirement| quote(requirement) }.join(", ")
  "#{line}, with: [#{formatted_with}]"
end

.dump_name(package) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



196
197
198
# File 'bundle/extensions/extension.rb', line 196

def self.dump_name(package)
  package.to_s
end

.dump_output(describe: false, no_restart: false) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • describe (Boolean) (defaults to: false)
  • no_restart (Boolean) (defaults to: false)

Returns:



211
212
213
214
215
216
# File 'bundle/extensions/extension.rb', line 211

def self.dump_output(describe: false, no_restart: false)
  _ = describe
  _ = no_restart

  dump
end

.dump_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


87
88
89
# File 'bundle/extensions/extension.rb', line 87

def self.dump_supported?
  true
end

.dump_with(_package) ⇒ Array<String>?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



201
202
203
# File 'bundle/extensions/extension.rb', line 201

def self.dump_with(_package)
  nil
end

.entry(name, options = {}) ⇒ Dsl::Entry

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



30
31
32
33
34
# File 'bundle/extensions/extension.rb', line 30

def self.entry(name, options = {})
  raise "unknown options(#{options.keys.inspect}) for #{type}" if options.present?

  Dsl::Entry.new(type, name)
end

.fetchable_name(name, options = {}, no_upgrade: false) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



153
154
155
156
157
158
159
# File 'bundle/extensions/extension.rb', line 153

def self.fetchable_name(name, options = {}, no_upgrade: false)
  _ = name
  _ = options
  _ = no_upgrade

  nil
end

.flagString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



37
38
39
# File 'bundle/extensions/extension.rb', line 37

def self.flag
  type.to_s.tr("_", "-")
end

.inherited(subclass) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



16
17
18
19
# File 'bundle/extensions/extension.rb', line 16

def self.inherited(subclass)
  super
  Homebrew::Bundle.register_extension(T.cast(subclass, T.class_of(Homebrew::Bundle::Extension)))
end

.install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **_options) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • preinstall (Boolean) (defaults to: true)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • _options (Homebrew::Bundle::EntryOption)

Returns:

  • (Boolean)


334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'bundle/extensions/extension.rb', line 334

def self.install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false,
                  **_options)
  _ = no_upgrade
  _ = force

  return true unless preinstall

  puts "Installing #{name} #{package_description}. It is not currently installed." if verbose
  return false unless install_package!(name, with:, verbose:)

  package = package_record(name, with:)
  installed_packages << package unless installed_packages.include?(package)
  packages << package unless packages.include?(package)
  true
end

.install_package!(name, with: nil, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


367
368
369
370
371
372
373
# File 'bundle/extensions/extension.rb', line 367

def self.install_package!(name, with: nil, verbose: false)
  _ = name
  _ = with
  _ = verbose

  raise NotImplementedError, "#{self} must override `install_package!` or `install!`."
end

.install_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


137
138
139
# File 'bundle/extensions/extension.rb', line 137

def self.install_supported?
  true
end

.install_verb(_name = "", _options = {}) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



142
143
144
# File 'bundle/extensions/extension.rb', line 142

def self.install_verb(_name = "", _options = {})
  "Installing"
end

.installed_packagesArray<T.untyped>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method is abstract.

Returns:



178
# File 'bundle/extensions/extension.rb', line 178

def self.installed_packages; end

.legacy_check_stepSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



250
251
252
# File 'bundle/extensions/extension.rb', line 250

def self.legacy_check_step
  :registered_extensions_to_install
end

.package_descriptionString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



82
83
84
# File 'bundle/extensions/extension.rb', line 82

def self.package_description
  check_label.downcase
end

.package_installed?(name, with: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


280
281
282
# File 'bundle/extensions/extension.rb', line 280

def self.package_installed?(name, with: nil)
  installed_packages.include?(package_record(name, with:))
end

.package_manager_env(executable) ⇒ Hash{String => String}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



67
68
69
# File 'bundle/extensions/extension.rb', line 67

def self.package_manager_env(executable)
  { "PATH" => "#{executable.dirname}:#{ORIGINAL_PATHS.join(":")}" }
end

.package_manager_executablePathname?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



57
58
59
# File 'bundle/extensions/extension.rb', line 57

def self.package_manager_executable
  which(package_manager_name, ORIGINAL_PATHS)
end

.package_manager_executable!Pathname

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



62
63
64
# File 'bundle/extensions/extension.rb', line 62

def self.package_manager_executable!
  package_manager_executable || raise("#{package_manager_name} is not installed")
end

.package_manager_installed?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


52
53
54
# File 'bundle/extensions/extension.rb', line 52

def self.package_manager_installed?
  package_manager_executable.present?
end

.package_manager_nameString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



47
48
49
# File 'bundle/extensions/extension.rb', line 47

def self.package_manager_name
  flag
end

.package_record(name, with: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



273
274
275
276
277
# File 'bundle/extensions/extension.rb', line 273

def self.package_record(name, with: nil)
  _ = with

  name
end

.packagesArray<T.untyped>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method is abstract.

Returns:



175
# File 'bundle/extensions/extension.rb', line 175

def self.packages; end

.predicate_methodSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



42
43
44
# File 'bundle/extensions/extension.rb', line 42

def self.predicate_method
  :"#{type}?"
end

.preinstall!(name, with: nil, no_upgrade: false, verbose: false, **_options) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'bundle/extensions/extension.rb', line 293

def self.preinstall!(name, with: nil, no_upgrade: false, verbose: false, **_options)
  _ = no_upgrade

  unless package_manager_installed?
    puts "Installing #{package_manager_name}. It is not currently installed." if verbose
    Bundle.system(HOMEBREW_BREW_FILE, "install", "--formula", package_manager_name, verbose:)
    # `formula_versions_from_env` consumes the env vars once at startup, so
    # keep the cached values across reset when bootstrapping a manager.
    formula_versions_from_env = T.let(
      Bundle.formula_versions_from_env_cache,
      T.nilable(T::Hash[String, String]),
    )
    upgrade_formulae = Bundle.upgrade_formulae
    Bundle.reset!
    Bundle.formula_versions_from_env_cache = formula_versions_from_env
    Bundle.upgrade_formulae = upgrade_formulae.join(",")
    unless package_manager_installed?
      raise "Unable to install #{name} #{package_description}. " \
            "#{package_manager_name} installation failed."
    end
  end

  if package_installed?(name, with:)
    puts "Skipping install of #{name} #{package_description}. It is already installed." if verbose
    return false
  end

  true
end

.quote(value) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



191
192
193
# File 'bundle/extensions/extension.rb', line 191

def self.quote(value)
  value.inspect
end

.remove_supported?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


132
133
134
# File 'bundle/extensions/extension.rb', line 132

def self.remove_supported?
  true
end

.reset!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method is abstract.

This method returns an undefined value.



172
# File 'bundle/extensions/extension.rb', line 172

def self.reset!; end

.switch_description(description) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



25
26
27
# File 'bundle/extensions/extension.rb', line 25

def self.switch_description(description)
  description
end

.uninstall_package!(name, executable: Pathname.new("")) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

Raises:

  • (NotImplementedError)


268
269
270
# File 'bundle/extensions/extension.rb', line 268

def self.uninstall_package!(name, executable: Pathname.new(""))
  raise NotImplementedError, "#{self} must override `uninstall_package!` or `cleanup!`."
end

.with_package_manager_env(&_blk) ⇒ T.type_parameter(:U)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • _blk (T.proc.params(executable: Pathname).returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U))


76
77
78
79
# File 'bundle/extensions/extension.rb', line 76

def self.with_package_manager_env(&_blk)
  executable = package_manager_executable!
  with_env(package_manager_env(executable)) { yield executable }
end

Instance Method Details

#failure_reason(package, no_upgrade:) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • package (Object)
  • no_upgrade (Boolean)

Returns:



351
352
353
# File 'bundle/extensions/extension.rb', line 351

def failure_reason(package, no_upgrade:)
  "#{self.class.check_label} #{self.class.dump_name(package)} needs to be installed."
end

#installed_and_up_to_date?(package, no_upgrade: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • package (Object)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


356
357
358
# File 'bundle/extensions/extension.rb', line 356

def installed_and_up_to_date?(package, no_upgrade: false)
  self.class.package_installed?(self.class.dump_name(package), with: self.class.dump_with(package))
end