Module: Homebrew::Settings Private

Defined in:
settings.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 reading and writing settings.

Class Method Summary collapse

Class Method Details

.delete(setting, repo: HOMEBREW_REPOSITORY) ⇒ void

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.

Parameters:



35
36
37
38
39
40
41
# File 'settings.rb', line 35

def self.delete(setting, repo: HOMEBREW_REPOSITORY)
  return unless (repo/".git/config").exist?

  return if read(setting, repo:).nil?

  Kernel.system("git", "-C", repo.to_s, "config", "--unset-all", "homebrew.#{setting}", exception: true)
end

.read(setting, repo: HOMEBREW_REPOSITORY) ⇒ 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.

Parameters:

Returns:



13
14
15
16
17
18
19
20
21
# File 'settings.rb', line 13

def self.read(setting, repo: HOMEBREW_REPOSITORY)
  return unless (repo/".git/config").exist?

  value = Utils.popen_read("git", "-C", repo.to_s, "config", "--get", "homebrew.#{setting}").chomp

  return if value.strip.empty?

  value
end

.write(setting, value, repo: HOMEBREW_REPOSITORY) ⇒ void

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.

Parameters:



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

def self.write(setting, value, repo: HOMEBREW_REPOSITORY)
  return unless (repo/".git/config").exist?

  value = value.to_s

  return if read(setting, repo:) == value

  Kernel.system("git", "-C", repo.to_s, "config", "--replace-all", "homebrew.#{setting}", value, exception: true)
end