Module: Cask::Caskroom Private

Extended by:
T::Sig
Defined in:
cask/caskroom.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. 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

.casks(config: nil) ⇒ Array<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.

Parameters:

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

Returns:



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

def self.casks(config: nil)
  return [] unless path.exist?

  Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
    token = path.basename.to_s

    if (tap_path = CaskLoader.tap_paths(token).first)
      CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
    elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first)
      CaskLoader::FromPathLoader.new(caskroom_path).load(config: config)
    else
      CaskLoader.load(token, config: config)
    end
  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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'cask/caskroom.rb', line 19

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: sudo)
  SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo)
  SystemCommand.run("/usr/sbin/chown", args: [User.current, path], sudo: sudo)
  SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo: 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:



14
15
16
# File 'cask/caskroom.rb', line 14

def self.path
  @path ||= HOMEBREW_PREFIX.join("Caskroom")
end