Module: Cask::Caskroom

Defined in:
cask/caskroom.rb

Overview

This module is part of an internal API. This module may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions for interacting with the Caskroom directory.

Class Method Summary collapse

Class Method Details

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


32
33
34
# File 'cask/caskroom.rb', line 32

def self.any_casks_installed?
  paths.any?
end

.casks(config: nil) ⇒ Array<Cask>

This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Get all installed casks.

Parameters:

  • config (Config, nil) (defaults to: nil)

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'cask/caskroom.rb', line 57

def self.casks(config: nil)
  tokens.sort.filter_map do |token|
    CaskLoader.load_prefer_installed(token, config:, warn: false)
  rescue TapCaskAmbiguityError => e
    T.must(e.loaders.first).load(config:)
  rescue
    # Don't blow up because of a single unavailable cask.
    nil
  end
end

.ensure_caskroom_existsvoid

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.

This method returns an undefined value.



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

def self.ensure_caskroom_exists
  return if path.exist?

  sudo = !path.parent.writable?

  if sudo && !ENV.key?("SUDO_ASKPASS") && $stdout.tty?
    ohai "Creating Caskroom directory: #{path}",
         "We'll set permissions properly so we won't need sudo in the future."
  end

  SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo:)
  SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo:)
  SystemCommand.run("/usr/sbin/chown", args: [User.current, path], sudo:)
  SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo:)
end

.pathPathname

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:



12
13
14
# File 'cask/caskroom.rb', line 12

def self.path
  @path ||= HOMEBREW_PREFIX/"Caskroom"
end

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

Return all tokens for installed casks.

Returns:



27
28
29
# File 'cask/caskroom.rb', line 27

def self.tokens
  paths.map { |path| path.basename.to_s }
end