Class: Cask::Cask

Inherits:
Object
  • Object
show all
Extended by:
Enumerable, Forwardable, Searchable
Includes:
Metadata
Defined in:
brew/Library/Homebrew/cask/cask.rb

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, &block) ⇒ Cask

Returns a new instance of Cask



36
37
38
39
40
41
42
# File 'brew/Library/Homebrew/cask/cask.rb', line 36

def initialize(token, sourcefile_path: nil, tap: nil, &block)
  @token = token
  @sourcefile_path = sourcefile_path
  @tap = tap
  @block = block
  self.config = Config.for_cask(self)
end

Instance Attribute Details

#configObject

Returns the value of attribute config



16
17
18
# File 'brew/Library/Homebrew/cask/cask.rb', line 16

def config
  @config
end

#sourcefile_pathObject (readonly)

Returns the value of attribute sourcefile_path



16
17
18
# File 'brew/Library/Homebrew/cask/cask.rb', line 16

def sourcefile_path
  @sourcefile_path
end

#tokenObject (readonly)

Returns the value of attribute token



16
17
18
# File 'brew/Library/Homebrew/cask/cask.rb', line 16

def token
  @token
end

Class Method Details

.eachObject



18
19
20
21
22
23
24
25
26
27
28
# File 'brew/Library/Homebrew/cask/cask.rb', line 18

def self.each
  return to_enum unless block_given?

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

Instance Method Details

#caskroom_pathObject



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

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

#config_pathObject



95
96
97
# File 'brew/Library/Homebrew/cask/cask.rb', line 95

def config_path
  /"config.json"
end

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

Returns:

  • (Boolean)


135
136
137
# File 'brew/Library/Homebrew/cask/cask.rb', line 135

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

#full_nameObject



72
73
74
75
76
77
# File 'brew/Library/Homebrew/cask/cask.rb', line 72

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

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

#hashObject



131
132
133
# File 'brew/Library/Homebrew/cask/cask.rb', line 131

def hash
  token.hash
end

#install_timeObject



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

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

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

#installed?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'brew/Library/Homebrew/cask/cask.rb', line 79

def installed?
  !versions.empty?
end

#installed_caskfileObject



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

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

#outdated?(greedy = false) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#outdated_versions(greedy = false) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'brew/Library/Homebrew/cask/cask.rb', line 107

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



30
31
32
33
34
# File 'brew/Library/Homebrew/cask/cask.rb', line 30

def tap
  return super if block_given? # Object#tap

  @tap
end

#timestamped_versionsObject



58
59
60
61
62
63
# File 'brew/Library/Homebrew/cask/cask.rb', line 58

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



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'brew/Library/Homebrew/cask/cask.rb', line 140

def to_h
  {
    "token"          => token,
    "name"           => name,
    "homepage"       => homepage,
    "url"            => url,
    "appcast"        => appcast,
    "version"        => version,
    "sha256"         => sha256,
    "artifacts"      => artifacts.map(&method(:to_h_gsubs)),
    "caveats"        => to_h_string_gsubs(caveats),
    "depends_on"     => depends_on,
    "conflicts_with" => conflicts_with,
    "container"      => container,
    "auto_updates"   => auto_updates,
  }
end

#to_sObject



127
128
129
# File 'brew/Library/Homebrew/cask/cask.rb', line 127

def to_s
  @token
end

#versionsObject



65
66
67
68
69
70
# File 'brew/Library/Homebrew/cask/cask.rb', line 65

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