Module: APIHashable Private
- Included in:
- Cask::Cask, Formula
- Defined in:
- api_hashable.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.
Used to substitute common paths with generic placeholders when generating JSON for the API.
Instance Method Summary collapse
- #deep_remove_placeholders(value) ⇒ T.type_parameter(:U) private
- #generated_hash! ⇒ void private
- #generating_hash! ⇒ void private
- #generating_hash? ⇒ Boolean private
Instance Method Details
#deep_remove_placeholders(value) ⇒ T.type_parameter(:U)
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'api_hashable.rb', line 43 def deep_remove_placeholders(value) return value if value = case value when Hash value.transform_values { |v| deep_remove_placeholders(v) } when Array value.map { |v| deep_remove_placeholders(v) } when String value.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home) .gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX) .gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR) else value end T.cast(value, T.type_parameter(:U)) end |
#generated_hash! ⇒ 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.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'api_hashable.rb', line 24 def generated_hash! return unless # Revert monkeypatches for API generation Object.send(:remove_const, :HOMEBREW_PREFIX) Object.const_set(:HOMEBREW_PREFIX, @old_homebrew_prefix) ENV["HOME"] = @old_home ENV["GIT_CONFIG_GLOBAL"] = @old_git_config_global @generating_hash = false end |
#generating_hash! ⇒ 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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'api_hashable.rb', line 7 def return if # Apply monkeypatches for API generation @old_homebrew_prefix = T.let(HOMEBREW_PREFIX, T.nilable(Pathname)) @old_homebrew_cellar = T.let(HOMEBREW_CELLAR, T.nilable(Pathname)) @old_home = T.let(Dir.home, T.nilable(String)) @old_git_config_global = T.let(ENV.fetch("GIT_CONFIG_GLOBAL", nil), T.nilable(String)) Object.send(:remove_const, :HOMEBREW_PREFIX) Object.const_set(:HOMEBREW_PREFIX, Pathname.new(HOMEBREW_PREFIX_PLACEHOLDER)) ENV["HOME"] = HOMEBREW_HOME_PLACEHOLDER ENV["GIT_CONFIG_GLOBAL"] = File.join(@old_home, ".gitconfig") @generating_hash = T.let(true, T.nilable(T::Boolean)) end |
#generating_hash? ⇒ 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.
37 38 39 40 |
# File 'api_hashable.rb', line 37 def @generating_hash ||= false @generating_hash == true end |