Class: AbstractTab Private
- Extended by:
- Cacheable, T::Generic, T::Helpers
- Defined in:
- tab.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Rather than calling new directly, use one of the class methods like Tab.create.
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[T.any(Pathname, String), T.untyped] } }
- FILENAME =
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.
"INSTALL_RECEIPT.json"- RuntimeDependencies =
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.
T.type_alias do T.nilable(T.any(T::Array[String], T::Array[T::Hash[String, T.untyped]], T::Hash[String, T.untyped], T::Hash[Symbol, T.untyped])) end
Instance Attribute Summary collapse
- #arch ⇒ String, ... private
- #built_on ⇒ Hash{String => T.untyped}? private
- #homebrew_version ⇒ String? private
-
#installed_on_request ⇒ Boolean
internal
Check whether the formula or cask was installed on request.
- #loaded_from_api ⇒ Boolean? private
- #loaded_from_internal_api ⇒ Boolean? private
-
#runtime_dependencies ⇒ RuntimeDependencies
internal
Returns the formula or cask runtime dependencies.
- #source ⇒ Hash{String => T.untyped} private
- #tabfile ⇒ Pathname? private
- #time ⇒ Integer? private
Class Method Summary collapse
-
.create(formula_or_cask) ⇒ T.attached_class
private
Instantiates a Tab for a new installation of a formula or cask.
- .empty ⇒ T.attached_class private
-
.from_file(path) ⇒ T.attached_class
private
Returns the Tab for a formula or cask install receipt at
path. -
.from_file_content(content, path) ⇒ T.attached_class
private
Like AbstractTab.from_file, but bypass the cache.
Instance Method Summary collapse
-
#initialize(homebrew_version: nil, tabfile: nil, loaded_from_api: nil, loaded_from_internal_api: nil, installed_on_request: nil, time: nil, arch: nil, source: nil, built_on: nil, runtime_dependencies: nil, **_unknown) ⇒ void
constructor
private
Unrecognised attributes are ignored so that receipts written by other Homebrew versions (e.g. the long-removed
installed_as_dependency) still load. - #installed_on_request_present? ⇒ Boolean private
- #parsed_homebrew_version ⇒ Version private
- #tap ⇒ Tap? private
- #tap=(tap) ⇒ void private
- #write ⇒ void private
Methods included from Cacheable
Constructor Details
#initialize(homebrew_version: nil, tabfile: nil, loaded_from_api: nil, loaded_from_internal_api: nil, installed_on_request: nil, time: nil, arch: nil, source: nil, built_on: nil, runtime_dependencies: nil, **_unknown) ⇒ 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.
Unrecognised attributes are ignored so that receipts written by other
Homebrew versions (e.g. the long-removed installed_as_dependency) still load.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'tab.rb', line 76 def initialize(homebrew_version: nil, tabfile: nil, loaded_from_api: nil, loaded_from_internal_api: nil, installed_on_request: nil, time: nil, arch: nil, source: nil, built_on: nil, runtime_dependencies: nil, **_unknown) resolved_installed_on_request = installed_on_request || false @installed_on_request = T.let(resolved_installed_on_request, T::Boolean) installed_on_request_present = !installed_on_request.nil? @installed_on_request_present = T.let(installed_on_request_present, T::Boolean) @homebrew_version = homebrew_version resolved_tabfile = Pathname(tabfile) unless tabfile.nil? @tabfile = T.let(resolved_tabfile, T.nilable(Pathname)) @loaded_from_api = loaded_from_api @loaded_from_internal_api = loaded_from_internal_api @time = time @arch = arch source ||= {} @source = T.let(source, T::Hash[String, T.untyped]) @built_on = built_on @runtime_dependencies = runtime_dependencies end |
Instance Attribute Details
#arch ⇒ 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.
47 48 49 |
# File 'tab.rb', line 47 def arch @arch end |
#built_on ⇒ Hash{String => T.untyped}?
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.
53 54 55 |
# File 'tab.rb', line 53 def built_on @built_on end |
#homebrew_version ⇒ 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.
32 33 34 |
# File 'tab.rb', line 32 def homebrew_version @homebrew_version end |
#installed_on_request ⇒ Boolean
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.
Check whether the formula or cask was installed on request.
29 30 31 |
# File 'tab.rb', line 29 def installed_on_request @installed_on_request end |
#loaded_from_api ⇒ 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.
38 39 40 |
# File 'tab.rb', line 38 def loaded_from_api @loaded_from_api end |
#loaded_from_internal_api ⇒ 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.
41 42 43 |
# File 'tab.rb', line 41 def loaded_from_internal_api @loaded_from_internal_api end |
#runtime_dependencies ⇒ RuntimeDependencies
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.
Returns the formula or cask runtime dependencies.
59 60 61 |
# File 'tab.rb', line 59 def runtime_dependencies @runtime_dependencies end |
#source ⇒ Hash{String => T.untyped}
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.
50 51 52 |
# File 'tab.rb', line 50 def source @source end |
#tabfile ⇒ Pathname?
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.
35 36 37 |
# File 'tab.rb', line 35 def tabfile @tabfile end |
#time ⇒ Integer?
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.
44 45 46 |
# File 'tab.rb', line 44 def time @time end |
Class Method Details
.create(formula_or_cask) ⇒ T.attached_class
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.
Instantiates a Tab for a new installation of a formula or cask.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'tab.rb', line 98 def self.create(formula_or_cask) new( homebrew_version: HOMEBREW_VERSION, installed_on_request: false, loaded_from_api: formula_or_cask.loaded_from_api?, loaded_from_internal_api: formula_or_cask.loaded_from_internal_api?, time: Time.now.to_i, arch: Hardware::CPU.arch, source: { "tap" => formula_or_cask.tap&.name, "tap_git_head" => formula_or_cask.tap_git_head, }, built_on: DevelopmentTools.build_system_info, ) end |
.empty ⇒ T.attached_class
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.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'tab.rb', line 141 def self.empty new( homebrew_version: HOMEBREW_VERSION, loaded_from_api: false, loaded_from_internal_api: false, time: nil, runtime_dependencies: nil, arch: nil, source: { "path" => nil, "tap" => nil, "tap_git_head" => nil, }, built_on: DevelopmentTools.build_system_info, ) end |
.from_file(path) ⇒ T.attached_class
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.
Results are cached.
Returns the Tab for a formula or cask install receipt at path.
118 119 120 121 122 123 124 125 |
# File 'tab.rb', line 118 def self.from_file(path) cache.fetch(path) do |p| content = File.read(p) return empty if content.blank? cache[p] = from_file_content(content, p) end end |
.from_file_content(content, path) ⇒ T.attached_class
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.
Like from_file, but bypass the cache.
129 130 131 132 133 134 135 136 137 138 |
# File 'tab.rb', line 129 def self.from_file_content(content, path) attributes = begin JSON.parse(content) rescue JSON::ParserError => e raise e, "Cannot parse #{path}: #{e}", e.backtrace end attributes["tabfile"] = path new(**attributes.transform_keys(&:to_sym)) end |
Instance Method Details
#installed_on_request_present? ⇒ 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.
181 |
# File 'tab.rb', line 181 def installed_on_request_present? = @installed_on_request_present |
#parsed_homebrew_version ⇒ Version
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.
173 174 175 176 177 178 |
# File 'tab.rb', line 173 def parsed_homebrew_version homebrew_version = self.homebrew_version return Version::NULL if homebrew_version.nil? Version.new(homebrew_version) end |
#tap ⇒ Tap?
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.
184 185 186 187 |
# File 'tab.rb', line 184 def tap tap_name = source["tap"] Tap.fetch(tap_name) if tap_name end |
#tap=(tap) ⇒ 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.
190 191 192 193 |
# File 'tab.rb', line 190 def tap=(tap) tap_name = tap.is_a?(Tap) ? tap.name : tap source["tap"] = tap_name end |
#write ⇒ 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.
196 197 198 199 200 201 202 |
# File 'tab.rb', line 196 def write tfile = tabfile raise "No tabfile to write to" unless tfile self.class.cache[tfile] = self tfile.atomic_write(to_json) end |