Class: Homebrew::Bundle::Cask Private

Inherits:
PackageType show all
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.

Constant Summary collapse

PACKAGE_TYPE =

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

:cask
PACKAGE_TYPE_NAME =

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

"Cask"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled

Methods inherited from PackageType

check, #checkable_entries, dump_supported?, #exit_early_check, #failure_reason, #find_actionable, #format_checkable, #full_check, inherited, install_supported?, type

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.

Parameters:

Returns:

  • (Boolean)


163
164
165
166
167
# File 'bundle/cask.rb', line 163

def cask_in_array?(cask, array)
  return true if array.include?(cask)

  array.include?(cask.split("/").last)
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.

Parameters:

Returns:

  • (Boolean)


170
171
172
173
174
175
176
177
178
179
180
181
# File 'bundle/cask.rb', line 170

def cask_installed?(cask)
  return true if cask_in_array?(cask, installed_casks)

  old_name = cask_oldnames[cask]
  old_name ||= cask_oldnames[cask.split("/").fetch(-1)]
  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.

Parameters:

  • cask (String)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


155
156
157
158
159
160
# File 'bundle/cask.rb', line 155

def cask_installed_and_up_to_date?(cask, no_upgrade: false)
  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.

Parameters:

Returns:

  • (Boolean)


212
213
214
215
216
217
218
219
# File 'bundle/cask.rb', line 212

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.outdated?(greedy: true)
end

.cask_namesArray<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:



199
200
201
# File 'bundle/cask.rb', line 199

def cask_names
  @cask_names ||= casks.map(&:to_s)
end

.cask_oldnamesHash{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.

Returns:



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'bundle/cask.rb', line 238

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 c.full_name.include? "/" # tap cask
        tap_name = c.full_name.rpartition("/").first
        hash["#{tap_name}/#{oldname}"] = c.full_name
      end
    end
  end
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.

Parameters:

Returns:

  • (Boolean)


184
185
186
# File 'bundle/cask.rb', line 184

def cask_upgradable?(cask)
  cask_in_array?(cask, outdated_casks)
end

.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.

Parameters:

  • describe (Boolean) (defaults to: false)

Returns:



222
223
224
225
226
227
228
# File 'bundle/cask.rb', line 222

def dump(describe: false)
  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?
    "#{description}cask \"#{cask.full_name}\"#{config}"
  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.

Parameters:

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

Returns:



231
232
233
234
235
# File 'bundle/cask.rb', line 231

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

  dump(describe:)
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:



144
145
146
147
148
149
150
151
152
# File 'bundle/cask.rb', line 144

def fetchable_name(name, options = {}, no_upgrade: false)
  full_name = T.cast(options.fetch(:full_name, name), String)
  user, repository, = full_name.split("/", 3)
  return if user.present? && repository.present? &&
            Homebrew::Bundle::Tap.installed_taps.exclude?("#{user}/#{repository}")
  return unless installable_or_upgradable?(name, no_upgrade:, **options)

  full_name
end

.formula_dependencies(cask_list) ⇒ 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:



254
255
256
257
258
259
260
261
262
263
# File 'bundle/cask.rb', line 254

def formula_dependencies(cask_list)
  return [] unless Bundle.cask_installed?
  return [] if cask_list.blank?

  casks.flat_map do |cask|
    next unless cask_list.include?(cask.to_s)

    cask.depends_on[: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.

Parameters:

  • name (String)
  • preinstall (Boolean) (defaults to: true)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • options (T.untyped)

Returns:

  • (Boolean)


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
# File 'bundle/cask.rb', line 93

def install!(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options)
  return true unless preinstall

  full_name = options.fetch(:full_name, name)

  install_result = if cask_installed?(name) && upgrading?(no_upgrade, name, options)
    status = "#{options[: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
    args = options.fetch(: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 "Installing #{name} cask#{with_args}. It is not currently installed." if verbose

    if Bundle.brew("install", "--cask", full_name, *args, verbose:)
      installed_casks << name
      true
    else
      false
    end
  end
  result = install_result

  if cask_installed?(name)
    postinstall_result = postinstall_change_state!(name:, options:, verbose:)
    result &&= postinstall_result
  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.



73
74
75
76
77
# File 'bundle/cask.rb', line 73

def install_verb(name, options = {})
  return "Installing" if !cask_installed?(name) || !upgrading?(false, name, options)

  "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.

Parameters:

  • name (String)
  • no_upgrade (Boolean) (defaults to: false)
  • options (T.untyped)

Returns:

  • (Boolean)


139
140
141
# File 'bundle/cask.rb', line 139

def installable_or_upgradable?(name, no_upgrade: false, **options)
  !cask_installed?(name) || upgrading?(no_upgrade, name, options)
end

.installed_casksArray<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:



189
190
191
# File 'bundle/cask.rb', line 189

def installed_casks
  @installed_casks ||= cask_names
end

.outdated_cask_namesArray<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:



204
205
206
207
208
209
# File 'bundle/cask.rb', line 204

def outdated_cask_names
  return [] unless Bundle.cask_installed?

  casks.select { |c| c.outdated?(greedy: false) }
       .map(&:to_s)
end

.outdated_casksArray<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:



194
195
196
# File 'bundle/cask.rb', line 194

def outdated_casks
  @outdated_casks ||= outdated_cask_names
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.

Parameters:

  • name (String)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • options (T.untyped)

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
# File 'bundle/cask.rb', line 80

def preinstall!(name, no_upgrade: false, verbose: false, **options)
  if cask_installed?(name) && !upgrading?(no_upgrade, name, options)
    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.



17
18
19
20
21
22
23
# File 'bundle/cask.rb', line 17

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

Instance Method Details

#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.

Parameters:

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

Returns:

  • (Boolean)


267
268
269
270
271
# File 'bundle/cask.rb', line 267

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