Class: Cask::Audit Private

Inherits:
Object
  • Object
show all
Extended by:
Predicable, T::Sig
Defined in:
cask/audit.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.

Audit a cask for various problems.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Predicable

attr_predicate

Constructor Details

#initialize(cask, appcast: nil, download: nil, quarantine: nil, token_conflicts: nil, online: nil, strict: nil, new_cask: nil) ⇒ Audit

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 a new instance of Audit.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'cask/audit.rb', line 25

def initialize(cask, appcast: nil, download: nil, quarantine: nil,
               token_conflicts: nil, online: nil, strict: nil,
               new_cask: nil)

  # `new_cask` implies `online` and `strict`
  online = new_cask if online.nil?
  strict = new_cask if strict.nil?

  # `online` implies `appcast` and `download`
  appcast = online if appcast.nil?
  download = online if download.nil?

  # `new_cask` implies `token_conflicts`
  token_conflicts = new_cask if token_conflicts.nil?

  @cask = cask
  @appcast = appcast
  @download = Download.new(cask, quarantine: quarantine) if download
  @online = online
  @strict = strict
  @new_cask = new_cask
  @token_conflicts = token_conflicts
end

Instance Attribute Details

#caskObject (readonly)

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.



21
22
23
# File 'cask/audit.rb', line 21

def cask
  @cask
end

#downloadObject (readonly)

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.



21
22
23
# File 'cask/audit.rb', line 21

def download
  @download
end

Instance Method Details

#add_error(message, location: 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.



99
100
101
# File 'cask/audit.rb', line 99

def add_error(message, location: nil)
  errors << ({ message: message, location: location })
end

#add_warning(message, location: 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.



103
104
105
106
107
108
109
# File 'cask/audit.rb', line 103

def add_warning(message, location: nil)
  if strict?
    add_error message, location: location
  else
    warnings << ({ message: message, location: location })
  end
end

#errorsObject

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.



91
92
93
# File 'cask/audit.rb', line 91

def errors
  @errors ||= []
end

#errors?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)


111
112
113
# File 'cask/audit.rb', line 111

def errors?
  errors.any?
end

#resultObject

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.



119
120
121
122
123
124
125
126
127
# File 'cask/audit.rb', line 119

def result
  if errors?
    Formatter.error("failed")
  elsif warnings?
    Formatter.warning("warning")
  else
    Formatter.success("passed")
  end
end

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'cask/audit.rb', line 49

def run!
  check_denylist
  check_reverse_migration
  check_required_stanzas
  check_version
  check_sha256
  check_desc
  check_url
  check_unnecessary_verified
  check_missing_verified
  check_no_match
  check_generic_artifacts
  check_token_valid
  check_token_bad_words
  check_token_conflicts
  check_languages
  check_download
  check_https_availability
  check_single_pre_postflight
  check_single_uninstall_zap
  check_untrusted_pkg
  livecheck_result = check_livecheck_version
  check_hosting_with_livecheck(livecheck_result: livecheck_result)
  check_appcast_and_livecheck
  check_latest_with_appcast_or_livecheck
  check_latest_with_auto_updates
  check_stanza_requires_uninstall
  check_appcast_contains_version
  check_gitlab_repository
  check_gitlab_repository_archived
  check_gitlab_prerelease_version
  check_github_repository
  check_github_repository_archived
  check_github_prerelease_version
  check_bitbucket_repository
  self
rescue => e
  odebug e, e.backtrace
  add_error "exception while auditing #{cask}: #{e.message}"
  self
end

#success?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)


149
150
151
# File 'cask/audit.rb', line 149

def success?
  !(errors? || warnings?)
end

#summary(include_passed: false, include_warnings: true) ⇒ 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:

  • include_passed (Boolean) (defaults to: false)
  • include_warnings (Boolean) (defaults to: true)

Returns:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'cask/audit.rb', line 130

def summary(include_passed: false, include_warnings: true)
  return if success? && !include_passed
  return if warnings? && !errors? && !include_warnings

  summary = ["audit for #{cask}: #{result}"]

  errors.each do |error|
    summary << " #{Formatter.error("-")} #{error[:message]}"
  end

  if include_warnings
    warnings.each do |warning|
      summary << " #{Formatter.warning("-")} #{warning[:message]}"
    end
  end

  summary.join("\n")
end

#warningsObject

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.



95
96
97
# File 'cask/audit.rb', line 95

def warnings
  @warnings ||= []
end

#warnings?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)


115
116
117
# File 'cask/audit.rb', line 115

def warnings?
  warnings.any?
end