Class: Cask::Cask Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Searchable, T::Sig
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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'cask/cask.rb', line 42

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

def self.all
  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.



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

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)


137
138
139
# File 'cask/cask.rb', line 137

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.



133
134
135
# File 'cask/cask.rb', line 133

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.



141
142
143
# File 'cask/cask.rb', line 141

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)


217
218
219
# File 'cask/cask.rb', line 217

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.



109
110
111
112
113
114
# File 'cask/cask.rb', line 109

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.



213
214
215
# File 'cask/cask.rb', line 213

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)


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

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)


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

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.



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

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.



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

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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'cask/cask.rb', line 92

def os_versions
  @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(token)
      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)


165
166
167
168
# File 'cask/cask.rb', line 165

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)


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

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.



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'cask/cask.rb', line 192

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.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'cask/cask.rb', line 170

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.



65
66
67
68
69
70
71
# File 'cask/cask.rb', line 65

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.



36
37
38
39
40
# File 'cask/cask.rb', line 36

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:



78
79
80
81
82
83
# File 'cask/cask.rb', line 78

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.



246
247
248
249
250
251
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
# File 'cask/cask.rb', line 246

def to_h
  hash = to_hash
  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|
        # Big Sur is the first version of macOS that supports arm
        next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)

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

        refresh

        bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch).to_sym
        to_hash.each do |key, value|
          next if hash_keys_to_skip.include? key
          next if value.to_s == hash[key].to_s

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

  Homebrew::SimulateSystem.clear
  refresh

  hash["variations"] = variations
  hash
end

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



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'cask/cask.rb', line 222

def to_hash
  {
    "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.map(&method(:to_h_gsubs)),
    "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_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.



209
210
211
# File 'cask/cask.rb', line 209

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.



85
86
87
88
89
90
# File 'cask/cask.rb', line 85

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