Class: Cask::Audit Private

Inherits:
Object
  • Object
show all
Extended by:
Predicable
Defined in:
Library/Homebrew/cask/audit.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Audit.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'Library/Homebrew/cask/audit.rb', line 22

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. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'Library/Homebrew/cask/audit.rb', line 18

def cask
  @cask
end

#downloadObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'Library/Homebrew/cask/audit.rb', line 18

def download
  @download
end

Instance Method Details

#add_error(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


90
91
92
# File 'Library/Homebrew/cask/audit.rb', line 90

def add_error(message)
  errors << message
end

#add_warning(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


94
95
96
97
98
99
100
# File 'Library/Homebrew/cask/audit.rb', line 94

def add_warning(message)
  if strict?
    add_error message
  else
    warnings << message
  end
end

#errorsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


82
83
84
# File 'Library/Homebrew/cask/audit.rb', line 82

def errors
  @errors ||= []
end

#errors?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

102
103
104
# File 'Library/Homebrew/cask/audit.rb', line 102

def errors?
  errors.any?
end

#resultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


110
111
112
113
114
115
116
117
118
# File 'Library/Homebrew/cask/audit.rb', line 110

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. You should avoid using this method if possible, as it may be removed or be changed in the future.


46
47
48
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
# File 'Library/Homebrew/cask/audit.rb', line 46

def run!
  check_denylist
  check_required_stanzas
  check_version
  check_sha256
  check_desc
  check_url
  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
  check_hosting_with_appcast
  check_latest_with_appcast
  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.message}\n#{e.backtrace.join("\n")}"
  add_error "exception while auditing #{cask}: #{e.message}"
  self
end

#success?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

134
135
136
# File 'Library/Homebrew/cask/audit.rb', line 134

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

#summaryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'Library/Homebrew/cask/audit.rb', line 120

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

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

  warnings.each do |warning|
    summary << " #{Formatter.warning("-")} #{warning}"
  end

  summary.join("\n")
end

#warningsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


86
87
88
# File 'Library/Homebrew/cask/audit.rb', line 86

def warnings
  @warnings ||= []
end

#warnings?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

106
107
108
# File 'Library/Homebrew/cask/audit.rb', line 106

def warnings?
  warnings.any?
end