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, &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.



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

def initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil, &block)
  @token = token
  @sourcefile_path = sourcefile_path
  @source = source
  @tap = tap
  @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

#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

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



24
25
26
27
28
29
30
31
32
# File 'cask/cask.rb', line 24

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.



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

def caskroom_path
  @caskroom_path ||= Caskroom.path.join(token)
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.



126
127
128
# File 'cask/cask.rb', line 126

def config_path
  /"config.json"
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)


193
194
195
# File 'cask/cask.rb', line 193

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.



102
103
104
105
106
107
# File 'cask/cask.rb', line 102

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.



189
190
191
# File 'cask/cask.rb', line 189

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)


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

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)


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

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.



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

def installed_caskfile
  installed_version = timestamped_versions.last
  .join(*installed_version, "Casks", "#{token}.rb")
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.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'cask/cask.rb', line 85

def os_versions
  @os_versions ||= begin
    version_os_hash = {}
    actual_version = MacOS.full_version.to_s

    MacOS::Version::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)


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

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_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.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'cask/cask.rb', line 168

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.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'cask/cask.rb', line 139

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

  if greedy || (greedy_latest && greedy_auto_updates) || (greedy_auto_updates && auto_updates)
    return versions if version.latest?
  elsif greedy_latest && version.latest?
    return versions
  elsif auto_updates
    return []
  end

  latest_version = if Homebrew::EnvConfig.install_from_api? &&
                      (latest_cask_version = Homebrew::API::Versions.latest_cask_version(token))
    DSL::Version.new latest_cask_version.to_s
  else
    version
  end

  installed = versions
  current   = installed.last

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

  # collect all installed versions that are different than tap version and return them
  installed.reject { |v| v == latest_version }
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.



34
35
36
37
38
# File 'cask/cask.rb', line 34

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:



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

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.



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'cask/cask.rb', line 198

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



185
186
187
# File 'cask/cask.rb', line 185

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.



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

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