Module: Homebrew::Settings Private

Extended by:
Cachable, T::Generic
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.

Constant Summary collapse

Cache =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

type_template { { fixed: T::Hash[Pathname, T::Hash[String, String]] } }

Class Method Summary collapse

Methods included from Cachable

cache, clear_cache

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:



42
43
44
45
46
47
48
49
# File 'settings.rb', line 42

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)
  cache.delete(repo)
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:



19
20
21
22
23
24
25
26
27
# File 'settings.rb', line 19

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

  value = all(repo)[setting.to_s]

  return if value.nil? || 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:



30
31
32
33
34
35
36
37
38
39
# File 'settings.rb', line 30

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)
  cache.delete(repo)
end