Class: Cask::Cask Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Searchable
Includes:
Metadata
Defined in:
cask/cask.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.

An instance of a cask.

Constant Summary

Constants included from Metadata

Metadata::METADATA_SUBDIR, Metadata::TIMESTAMP_FORMAT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Searchable

search

Methods included from Metadata

#metadata_main_container_path, #metadata_subdir, #metadata_timestamped_path, #metadata_versioned_path

Constructor Details

#initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil, allow_reassignment: false, &block) ⇒ 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.

Returns a new instance of Cask.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'cask/cask.rb', line 47

def initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil, allow_reassignment: false, &block)
  @token = token
  @sourcefile_path = sourcefile_path
  @source = source
  @tap = tap
  @allow_reassignment = allow_reassignment
  @block = block

  @default_config = config || Config.new

  self.config = if config_path.exist?
    Config.from_json(File.read(config_path), ignore_invalid_keys: true)
  else
    @default_config
  end
end

Instance Attribute Details

#allow_reassignmentObject

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.



24
25
26
# File 'cask/cask.rb', line 24

def allow_reassignment
  @allow_reassignment
end

#configObject

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.



22
23
24
# File 'cask/cask.rb', line 22

def config
  @config
end

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



22
23
24
# File 'cask/cask.rb', line 22

def default_config
  @default_config
end

#downloadObject

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.



24
25
26
# File 'cask/cask.rb', line 24

def download
  @download
end

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



22
23
24
# File 'cask/cask.rb', line 22

def source
  @source
end

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



22
23
24
# File 'cask/cask.rb', line 22

def sourcefile_path
  @sourcefile_path
end

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



22
23
24
# File 'cask/cask.rb', line 22

def token
  @token
end

Class Method Details

.allObject

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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'cask/cask.rb', line 26

def self.all
  # TODO: uncomment for 3.7.0 and ideally avoid using ARGV by moving to e.g. CLI::Parser
  # if !ARGV.include?("--eval-all") && !Homebrew::EnvConfig.eval_all?
  #   odeprecated "Cask::Cask#all without --all or HOMEBREW_EVAL_ALL"
  # end

  Tap.flat_map(&:cask_files).map do |f|
    CaskLoader::FromTapPathLoader.new(f).load(config: nil)
  rescue CaskUnreadableError => e
    opoo e.message

    nil
  end.compact
end

Instance Method Details

#caskroom_pathObject

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.



167
168
169
# File 'cask/cask.rb', line 167

def caskroom_path
  @caskroom_path ||= Caskroom.path.join(token)
end

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


143
144
145
# File 'cask/cask.rb', line 143

def checksumable?
  DownloadStrategyDetector.detect(url.to_s, url.using) <= AbstractFileDownloadStrategy
end

#config_pathObject

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.



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

def config_path
  /"config.json"
end

#download_sha_pathObject

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.



147
148
149
# File 'cask/cask.rb', line 147

def download_sha_path
  /"LATEST_DOWNLOAD_SHA256"
end

#eql?(other) ⇒ Boolean Also known as: ==

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)


223
224
225
# File 'cask/cask.rb', line 223

def eql?(other)
  instance_of?(other.class) && token == other.token
end

#full_nameObject

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.



115
116
117
118
119
120
# File 'cask/cask.rb', line 115

def full_name
  return token if tap.nil?
  return token if tap.user == "Homebrew"

  "#{tap.name}/#{token}"
end

#hashObject

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.



219
220
221
# File 'cask/cask.rb', line 219

def hash
  token.hash
end

#install_timeTime?

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:

  • (Time, nil)


127
128
129
130
131
132
# File 'cask/cask.rb', line 127

def install_time
  _, time = timestamped_versions.last
  return unless time

  Time.strptime(time, Metadata::TIMESTAMP_FORMAT)
end

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


122
123
124
# File 'cask/cask.rb', line 122

def installed?
  !versions.empty?
end

#installed_caskfileObject

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.



134
135
136
137
# File 'cask/cask.rb', line 134

def installed_caskfile
  installed_version = timestamped_versions.last
  .join(*installed_version, "Casks", "#{token}.rb")
end

#new_download_shaObject

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

def new_download_sha
  require "cask/installer"

  # Call checksumable? before hashing
  @new_download_sha ||= Installer.new(self, verify_download_integrity: false)
                                 .download(quiet: true)
                                 .instance_eval { |x| Digest::SHA256.file(x).hexdigest }
end

#os_versionsObject

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.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'cask/cask.rb', line 97

def os_versions
  # TODO: use #to_hash_with_variations instead once all casks use on_system blocks
  @os_versions ||= begin
    version_os_hash = {}
    actual_version = MacOS.full_version.to_s

    MacOSVersions::SYMBOLS.each do |os_name, os_version|
      MacOS.full_version = os_version
      cask = CaskLoader.load(full_name)
      version_os_hash[os_name] = cask.version if cask.version != version
    end

    version_os_hash
  ensure
    MacOS.full_version = actual_version
  end
end

#outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: 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.

Returns:

  • (Boolean)


171
172
173
174
# File 'cask/cask.rb', line 171

def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false)
  !outdated_versions(greedy: greedy, greedy_latest: greedy_latest,
                     greedy_auto_updates: greedy_auto_updates).empty?
end

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


160
161
162
163
164
165
# File 'cask/cask.rb', line 160

def outdated_download_sha?
  return true unless checksumable?

  current_download_sha = download_sha_path.read if download_sha_path.exist?
  current_download_sha.blank? || current_download_sha != new_download_sha
end

#outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates) ⇒ 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.



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'cask/cask.rb', line 198

def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates)
  return token if !verbose && !json

  installed_versions = outdated_versions(greedy: greedy, greedy_latest: greedy_latest,
                                         greedy_auto_updates: greedy_auto_updates).join(", ")

  if json
    {
      name:               token,
      installed_versions: installed_versions,
      current_version:    version,
    }
  else
    "#{token} (#{installed_versions}) != #{version}"
  end
end

#outdated_versions(greedy: false, greedy_latest: false, greedy_auto_updates: false) ⇒ 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.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'cask/cask.rb', line 176

def outdated_versions(greedy: false, greedy_latest: false, greedy_auto_updates: false)
  # special case: tap version is not available
  return [] if version.nil?

  if version.latest?
    return versions if (greedy || greedy_latest) && outdated_download_sha?

    return []
  elsif auto_updates && !greedy && !greedy_auto_updates
    return []
  end

  installed = versions
  current   = installed.last

  # not outdated unless there is a different version on tap
  return [] if current == version

  # collect all installed versions that are different than tap version and return them
  installed.reject { |v| v == version }
end

#refreshObject

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.



70
71
72
73
74
75
76
# File 'cask/cask.rb', line 70

def refresh
  @dsl = DSL.new(self)
  return unless @block

  @dsl.instance_eval(&@block)
  @dsl.language_eval
end

#tapObject

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.



41
42
43
44
45
# File 'cask/cask.rb', line 41

def tap
  return super if block_given? # Object#tap

  @tap
end

#timestamped_versionsArray<Array(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:



83
84
85
86
87
88
# File 'cask/cask.rb', line 83

def timestamped_versions
  Pathname.glob((version: "*", timestamp: "*"))
          .map { |p| p.relative_path_from(p.parent.parent) }
          .sort_by(&:basename) # sort by timestamp
          .map { |p| p.split.map(&:to_s) }
end

#to_hObject

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.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'cask/cask.rb', line 228

def to_h
  {
    "token"          => token,
    "full_token"     => full_name,
    "tap"            => tap&.name,
    "name"           => name,
    "desc"           => desc,
    "homepage"       => homepage,
    "url"            => url,
    "appcast"        => appcast,
    "version"        => version,
    "versions"       => os_versions,
    "installed"      => versions.last,
    "outdated"       => outdated?,
    "sha256"         => sha256,
    "artifacts"      => artifacts_list,
    "caveats"        => (to_h_string_gsubs(caveats) unless caveats.empty?),
    "depends_on"     => depends_on,
    "conflicts_with" => conflicts_with,
    "container"      => container,
    "auto_updates"   => auto_updates,
  }
end

#to_hash_with_variationsObject

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.



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'cask/cask.rb', line 252

def to_hash_with_variations
  hash = to_h
  variations = {}

  hash_keys_to_skip = %w[outdated installed versions]

  if @dsl.on_system_blocks_exist?
    [:arm, :intel].each do |arch|
      MacOSVersions::SYMBOLS.each_key do |os_name|
        bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch)
        next unless bottle_tag.valid_combination?

        Homebrew::SimulateSystem.os = os_name
        Homebrew::SimulateSystem.arch = arch

        refresh

        to_h.each do |key, value|
          next if hash_keys_to_skip.include? key
          next if value.to_s == hash[key].to_s

          variations[bottle_tag.to_sym] ||= {}
          variations[bottle_tag.to_sym][key] = value
        end
      end
    end
  end

  Homebrew::SimulateSystem.clear
  refresh

  hash["variations"] = variations
  hash
end

#to_sObject

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.



215
216
217
# File 'cask/cask.rb', line 215

def to_s
  @token
end

#versionsObject

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.



90
91
92
93
94
95
# File 'cask/cask.rb', line 90

def versions
  timestamped_versions.map(&:first)
                      .reverse
                      .uniq
                      .reverse
end