Class: Homebrew::Bundle::Cask Private
- Inherits:
-
PackageType
- Object
- PackageType
- Homebrew::Bundle::Cask
- Extended by:
- Utils::Output::Mixin
- Defined in:
- bundle/cask.rb
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.
Class Method Summary collapse
- .cask_in_array?(cask, array) ⇒ Boolean private
- .cask_installed?(cask) ⇒ Boolean private
- .cask_installed_and_up_to_date?(cask, no_upgrade: false) ⇒ Boolean private
- .cask_is_outdated_using_greedy?(cask_name) ⇒ Boolean private
- .cask_names ⇒ Array<String> private
- .cask_oldnames ⇒ Hash{String => String} private
- .cask_tap_changed?(name, options = {}) ⇒ Boolean private
- .cask_upgradable?(cask) ⇒ Boolean private
- .casks ⇒ Array<::Cask::Cask> private
- .check_label ⇒ String private
- .dump(describe: false) ⇒ String private
- .dump_output(describe: false, no_restart: false) ⇒ String private
-
.formula_dependencies(cask_list, recursive: false) ⇒ Array<String>
private
Returns direct formula dependencies, preferring installed casks.
- .install!(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ Boolean private
- .install_verb(name, options = {}) ⇒ Object private
- .installable_or_upgradable?(name, no_upgrade: false, **options) ⇒ Boolean private
- .installed_casks ⇒ Array<String> private
- .outdated_cask_names ⇒ Array<String> private
- .outdated_casks ⇒ Array<String> private
- .pin_needed?(name, options) ⇒ Boolean private
- .preinstall!(name, no_upgrade: false, verbose: false, **options) ⇒ Boolean private
- .reset! ⇒ void private
- .type ⇒ Symbol private
Instance Method Summary collapse
- #format_checkable(entries) ⇒ Array<Object> private
- #installed_and_up_to_date?(cask, no_upgrade: false) ⇒ Boolean private
Methods included from Utils::Output::Mixin
issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_once, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_cannot_install, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_removed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning
Methods inherited from PackageType
batch_installable?, check, #checkable_entries, dump_supported?, #exit_early_check, #failure_reason, #find_actionable, #full_check, inherited, install_batch!, install_supported?
Class Method Details
.cask_in_array?(cask, array) ⇒ 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.
173 174 175 176 177 |
# File 'bundle/cask.rb', line 173 def cask_in_array?(cask, array) return true if array.include?(cask) array.include?(Utils.name_from_full_name(cask)) end |
.cask_installed?(cask) ⇒ 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.
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'bundle/cask.rb', line 180 def cask_installed?(cask) return true if cask_in_array?(cask, installed_casks) old_name = cask_oldnames[cask] old_name ||= cask_oldnames[Utils.name_from_full_name(cask)] return false unless old_name return false unless cask_in_array?(old_name, installed_casks) opoo "#{cask} was renamed to #{old_name}" true end |
.cask_installed_and_up_to_date?(cask, 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.
151 152 153 154 155 156 157 |
# File 'bundle/cask.rb', line 151 def cask_installed_and_up_to_date?(cask, no_upgrade: false) return false if cask_tap_changed?(cask) return false unless cask_installed?(cask) return true if no_upgrade !cask_upgradable?(cask) end |
.cask_is_outdated_using_greedy?(cask_name) ⇒ 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.
230 231 232 233 234 235 236 237 |
# File 'bundle/cask.rb', line 230 def cask_is_outdated_using_greedy?(cask_name) return false unless Bundle.cask_installed? cask = casks.find { |installed_cask| installed_cask.to_s == cask_name } return false if cask.nil? || cask.pinned? cask.outdated?(greedy: true) end |
.cask_names ⇒ 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.
216 217 218 |
# File 'bundle/cask.rb', line 216 def cask_names @cask_names ||= casks.map(&:to_s) end |
.cask_oldnames ⇒ 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.
260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'bundle/cask.rb', line 260 def cask_oldnames @cask_oldnames ||= casks.each_with_object({}) do |c, hash| oldnames = c.old_tokens next if oldnames.blank? oldnames.each do |oldname| hash[oldname] = c.full_name if (tap_name = Utils.tap_from_full_name(c.full_name)) hash["#{tap_name}/#{oldname}"] = c.full_name end end end end |
.cask_tap_changed?(name, 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.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'bundle/cask.rb', line 160 def cask_tap_changed?(name, = {}) full_name = .fetch(:full_name, name) return false unless full_name.is_a?(String) return false unless Utils.full_name?(full_name) require "cask/cask_loader" return false unless (token_tap_type = ::Cask::CaskLoader.tap_cask_token_type(full_name, warn: false)) token, tap, = token_tap_type casks.any? { |cask| cask.to_s == token && cask.tap != tap } end |
.cask_upgradable?(cask) ⇒ 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.
194 195 196 |
# File 'bundle/cask.rb', line 194 def cask_upgradable?(cask) cask_in_array?(cask, outdated_casks) end |
.casks ⇒ Array<::Cask::Cask>
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.
31 32 33 34 35 36 |
# File 'bundle/cask.rb', line 31 def casks return [] unless Bundle.cask_installed? require "cask/caskroom" @casks ||= T.let(::Cask::Caskroom.casks, T.nilable(T::Array[::Cask::Cask])) end |
.check_label ⇒ 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.
19 |
# File 'bundle/cask.rb', line 19 def check_label = "Cask" |
.dump(describe: 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.
240 241 242 243 244 245 246 247 248 249 250 |
# File 'bundle/cask.rb', line 240 def dump(describe: false) trusted_casks = Homebrew::Trust.trusted_entries(:cask) casks.map do |cask| description = "# #{cask.desc}\n" if describe && cask.desc.present? config = ", args: { #{explicit_s(cask.config)} }" if cask.config.present? && cask.config.explicit.present? caskline = "#{description}cask \"#{cask.full_name}\"#{config}" caskline += ", pin: true" if cask.pinned? caskline += ", trusted: true" if trusted_casks.include?(cask.full_name) caskline end.join("\n") 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.
253 254 255 256 257 |
# File 'bundle/cask.rb', line 253 def dump_output(describe: false, no_restart: false) _ = no_restart dump(describe:) end |
.formula_dependencies(cask_list, recursive: 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.
Returns direct formula dependencies, preferring installed casks. Recursive queries include all declared formula dependencies from current cask definitions and raise if a cask is unavailable.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'bundle/cask.rb', line 278 def formula_dependencies(cask_list, recursive: false) return [] if cask_list.blank? require "cask/cask_loader" installed_cask_objects = recursive ? [] : casks cask_list.flat_map do |cask_name| cask = installed_cask_objects.find do |installed_cask| cask_name == installed_cask.to_s || cask_name == installed_cask.full_name end cask ||= begin ::Cask::CaskLoader.load(cask_name) rescue ::Cask::CaskUnavailableError raise if recursive nil end next unless cask next cask.depends_on[:formula] unless recursive require "bundle/brew" require "formula" require "utils/topological_hash" Brew.formula_names_with_dependencies( ::Utils::TopologicalHash.graph_package_dependencies(cask).keys.grep(Formula), ) end.compact end |
.install!(name, 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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'bundle/cask.rb', line 74 def install!(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **) return true unless preinstall full_name = T.cast(.fetch(:full_name, name), String) # Only fully-qualified names map to a tap, so unqualified tokens # cannot be meaningfully trusted. Homebrew::Trust.trust!(:cask, full_name) if [:trusted] && Utils.full_name?(full_name) tap_changed = cask_tap_changed?(name, ) if tap_changed && casks.any? { |cask| cask.to_s == name && cask.pinned? } onoe "#{name} is pinned. Run `brew unpin --cask #{name}` before changing taps." return false end pin_only = !tap_changed && cask_installed?(name) && !upgrading?(no_upgrade, name, ) install_result = if pin_only true elsif !tap_changed && cask_installed?(name) status = "#{[:greedy] ? "may not be" : "not"} up-to-date" puts "Upgrading #{name} cask. It is installed but #{status}." if verbose Bundle.brew("upgrade", "--cask", full_name, verbose:) else cask_args = .fetch(:args, {}) args = (cask_args.is_a?(Hash) ? cask_args : {}).filter_map do |k, v| case v when TrueClass "--#{k}" when FalseClass, NilClass nil else "--#{k}=#{v}" end end args << "--force" if force args << "--adopt" unless args.include?("--force") args.uniq! with_args = " with #{args.join(" ")}" if args.present? puts "#{tap_changed ? "Reinstalling" : "Installing"} #{full_name} cask#{with_args}." if verbose if Bundle.brew(tap_changed ? "reinstall" : "install", "--cask", full_name, *args, verbose:) installed_casks << name true else false end end result = install_result if cask_installed?(name) pin_result = pin_change_state!(name:, full_name:, options:, verbose:) result &&= pin_result unless pin_only postinstall_result = postinstall_change_state!(name:, options:, verbose:) result &&= postinstall_result end end if tap_changed && install_result ::Cask::Tab.clear_cache reset! end result end |
.install_verb(name, options = {}) ⇒ 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.
44 45 46 47 48 49 50 |
# File 'bundle/cask.rb', line 44 def install_verb(name, = {}) return "Reinstalling" if cask_tap_changed?(name, ) return "Pinning" if pin_needed?(name, ) return "Installing" if !cask_installed?(name) || !upgrading?(false, name, ) "Upgrading" end |
.installable_or_upgradable?(name, no_upgrade: 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.
146 147 148 |
# File 'bundle/cask.rb', line 146 def installable_or_upgradable?(name, no_upgrade: false, **) !cask_installed?(name) || upgrading?(no_upgrade, name, ) end |
.installed_casks ⇒ 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.
206 207 208 |
# File 'bundle/cask.rb', line 206 def installed_casks @installed_casks ||= cask_names end |
.outdated_cask_names ⇒ 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.
221 222 223 224 225 226 227 |
# File 'bundle/cask.rb', line 221 def outdated_cask_names return [] unless Bundle.cask_installed? casks.reject(&:pinned?) .select { |c| c.outdated?(greedy: false) } .map(&:to_s) end |
.outdated_casks ⇒ 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.
211 212 213 |
# File 'bundle/cask.rb', line 211 def outdated_casks @outdated_casks ||= outdated_cask_names end |
.pin_needed?(name, 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.
199 200 201 202 203 |
# File 'bundle/cask.rb', line 199 def pin_needed?(name, ) return false if [:pin] != true || !cask_installed?(name) casks.none? { |cask| cask.to_s == name && cask.pinned? } end |
.preinstall!(name, 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.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'bundle/cask.rb', line 57 def preinstall!(name, no_upgrade: false, verbose: false, **) return true if cask_tap_changed?(name, ) if cask_installed?(name) && !upgrading?(no_upgrade, name, ) return true if pin_needed?(name, ) puts "Skipping install of #{name} cask. It is already installed." if verbose return false end 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 returns an undefined value.
22 23 24 25 26 27 28 |
# File 'bundle/cask.rb', line 22 def reset! @casks = T.let(nil, T.nilable(T::Array[::Cask::Cask])) @cask_names = T.let(nil, T.nilable(T::Array[String])) @cask_oldnames = T.let(nil, T.nilable(T::Hash[String, String])) @installed_casks = T.let(nil, T.nilable(T::Array[String])) @outdated_casks = T.let(nil, T.nilable(T::Array[String])) end |
.type ⇒ Symbol
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.
16 |
# File 'bundle/cask.rb', line 16 def type = :cask |
Instance Method Details
#format_checkable(entries) ⇒ Array<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.
353 354 355 |
# File 'bundle/cask.rb', line 353 def format_checkable(entries) checkable_entries(entries).map { |entry| entry..fetch(:full_name, entry.name).to_s.downcase } end |
#installed_and_up_to_date?(cask, 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.
358 359 360 361 362 |
# File 'bundle/cask.rb', line 358 def installed_and_up_to_date?(cask, no_upgrade: false) raise "cask must be a String, got #{cask.class}: #{cask}" unless cask.is_a?(String) self.class.cask_installed_and_up_to_date?(cask, no_upgrade:) end |