Module: Homebrew::Livecheck::SkipConditions Private

Defined in:
livecheck/skip_conditions.rb

Overview

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

The Livecheck::SkipConditions module primarily contains methods that check for various formula/cask/resource conditions where a check should be skipped.

Class Method Summary collapse

Class Method Details

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.

Prints default livecheck output in relation to skip conditions.

Parameters:



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'livecheck/skip_conditions.rb', line 314

def self.print_skip_information(skip_hash)
  return unless skip_hash.is_a?(Hash)

  name = if skip_hash[:formula].is_a?(String)
    skip_hash[:formula]
  elsif skip_hash[:cask].is_a?(String)
    skip_hash[:cask]
  elsif skip_hash[:resource].is_a?(String)
    "  #{skip_hash[:resource]}"
  end
  return unless name

  if skip_hash[:messages].is_a?(Array) && skip_hash[:messages].count.positive?
    # TODO: Handle multiple messages, only if needed in the future
    if skip_hash[:status] == "skipped"
      puts "#{Tty.red}#{name}#{Tty.reset}: skipped - #{skip_hash[:messages][0]}"
    else
      puts "#{Tty.red}#{name}#{Tty.reset}: #{skip_hash[:messages][0]}"
    end
  elsif skip_hash[:status].present?
    puts "#{Tty.red}#{name}#{Tty.reset}: #{skip_hash[:status]}"
  end
end

.referenced_skip_information(livecheck_package_or_resource, original_package_or_resource_name, full_name: false, verbose: false, extract_plist: true) ⇒ Hash{Symbol => 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.

Skip conditions for formulae/casks/resources referenced in a livecheck block are treated differently than normal. We only respect certain skip conditions (returning the related hash) and others are treated as errors.

Parameters:

  • livecheck_package_or_resource (Formula, Cask::Cask, Resource)
  • original_package_or_resource_name (String)
  • full_name (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • extract_plist (Boolean) (defaults to: true)

Returns:



272
273
274
275
276
277
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
307
308
309
310
# File 'livecheck/skip_conditions.rb', line 272

def self.referenced_skip_information(
  livecheck_package_or_resource,
  original_package_or_resource_name,
  full_name: false,
  verbose: false,
  extract_plist: true
)
  skip_info = SkipConditions.skip_information(
    livecheck_package_or_resource,
    full_name:,
    verbose:,
    extract_plist:,
  )
  return if skip_info.blank?

  referenced_name = Livecheck.package_or_resource_name(livecheck_package_or_resource, full_name:)
  referenced_type = case livecheck_package_or_resource
  when Formula
    :formula
  when Cask::Cask
    :cask
  when Resource
    :resource
  end

  if skip_info[:status] != "error" &&
     !(skip_info[:status] == "skipped" && livecheck_package_or_resource.livecheck.skip?)
    error_msg_end = if skip_info[:status] == "skipped"
      "automatically skipped"
    else
      "skipped as #{skip_info[:status]}"
    end

    raise "Referenced #{referenced_type} (#{referenced_name}) is #{error_msg_end}"
  end

  skip_info[referenced_type] = original_package_or_resource_name
  skip_info
end

.skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true) ⇒ Hash{Symbol => 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.

If a formula/cask/resource should be skipped, we return a hash from Livecheck#status_hash, which contains a status type and sometimes error messages.

Parameters:

  • package_or_resource (Formula, Cask::Cask, Resource)
  • full_name (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • extract_plist (Boolean) (defaults to: true)

Returns:



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'livecheck/skip_conditions.rb', line 234

def self.skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
  livecheckable = package_or_resource.livecheckable?

  checks = case package_or_resource
  when Formula
    FORMULA_CHECKS
  when Cask::Cask
    CASK_CHECKS
  when Resource
    RESOURCE_CHECKS
  end

  checks.each do |method_name|
    skip_hash = case method_name
    when :cask_extract_plist
      send(method_name, package_or_resource, livecheckable, full_name:, verbose:, extract_plist:)
    else
      send(method_name, package_or_resource, livecheckable, full_name:, verbose:)
    end
    return skip_hash if skip_hash.present?
  end

  {}
end