Class: Cask::Cask Private

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

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_master_container_path, #metadata_subdir, #metadata_timestamped_path, #metadata_versioned_path

Constructor Details

#initialize(token, sourcefile_path: nil, tap: nil, config: nil, &block) ⇒ Cask

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


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'Library/Homebrew/cask/cask.rb', line 38

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

  @default_config = config || Config.new

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

Instance Attribute Details

#configObject

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.


20
21
22
# File 'Library/Homebrew/cask/cask.rb', line 20

def config
  @config
end

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


20
21
22
# File 'Library/Homebrew/cask/cask.rb', line 20

def default_config
  @default_config
end

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


20
21
22
# File 'Library/Homebrew/cask/cask.rb', line 20

def sourcefile_path
  @sourcefile_path
end

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


20
21
22
# File 'Library/Homebrew/cask/cask.rb', line 20

def token
  @token
end

Class Method Details

.each(&block) ⇒ 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.


22
23
24
25
26
27
28
29
30
# File 'Library/Homebrew/cask/cask.rb', line 22

def self.each(&block)
  return to_enum unless block_given?

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

Instance Method Details

#caskroom_pathObject

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.


108
109
110
# File 'Library/Homebrew/cask/cask.rb', line 108

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

#config_pathObject

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.


104
105
106
# File 'Library/Homebrew/cask/cask.rb', line 104

def config_path
  /"config.json"
end

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

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)

160
161
162
# File 'Library/Homebrew/cask/cask.rb', line 160

def eql?(other)
  token == other.token
end

#full_nameObject

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.


81
82
83
84
85
86
# File 'Library/Homebrew/cask/cask.rb', line 81

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


156
157
158
# File 'Library/Homebrew/cask/cask.rb', line 156

def hash
  token.hash
end

#install_timeObject

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.


92
93
94
95
96
97
# File 'Library/Homebrew/cask/cask.rb', line 92

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

Returns:

  • (Boolean)

88
89
90
# File 'Library/Homebrew/cask/cask.rb', line 88

def installed?
  !versions.empty?
end

#installed_caskfileObject

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.


99
100
101
102
# File 'Library/Homebrew/cask/cask.rb', line 99

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

#outdated?(greedy: false) ⇒ 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)

112
113
114
# File 'Library/Homebrew/cask/cask.rb', line 112

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

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


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'Library/Homebrew/cask/cask.rb', line 136

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

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

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

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


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'Library/Homebrew/cask/cask.rb', line 116

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

  if greedy
    return versions if version.latest?
  elsif 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

#tapObject

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.


32
33
34
35
36
# File 'Library/Homebrew/cask/cask.rb', line 32

def tap
  return super if block_given? # Object#tap

  @tap
end

#timestamped_versionsObject

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.


67
68
69
70
71
72
# File 'Library/Homebrew/cask/cask.rb', line 67

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


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

def to_h
  {
    "token"          => token,
    "name"           => name,
    "desc"           => desc,
    "homepage"       => homepage,
    "url"            => url,
    "appcast"        => appcast,
    "version"        => version,
    "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. You should avoid using this method if possible, as it may be removed or be changed in the future.


152
153
154
# File 'Library/Homebrew/cask/cask.rb', line 152

def to_s
  @token
end

#versionsObject

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.


74
75
76
77
78
79
# File 'Library/Homebrew/cask/cask.rb', line 74

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