Class: AbstractTab Abstract Private

Inherits:
Object show all
Extended by:
Cachable, 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.

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Rather than calling new directly, use one of the class methods like Tab.create.

Direct Known Subclasses

Cask::Tab, Tab

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cachable

cache, clear_cache

Constructor Details

#initialize(attributes = {}) ⇒ 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.

TODO:

Update attributes to only accept symbol keys (kwargs style).

Parameters:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'tab.rb', line 68

def initialize(attributes = {})
  @installed_as_dependency = T.let(false, T::Boolean)
  @installed_on_request = T.let(false, T::Boolean)
  @installed_on_request_present = T.let(false, T::Boolean)
  @homebrew_version = T.let(nil, T.nilable(String))
  @tabfile = T.let(nil, T.nilable(Pathname))
  @loaded_from_api = T.let(nil, T.nilable(T::Boolean))
  @loaded_from_internal_api = T.let(nil, T.nilable(T::Boolean))
  @time = T.let(nil, T.nilable(Integer))
  @arch = T.let(nil, T.nilable(T.any(String, Symbol)))
  @source = T.let({}, T::Hash[String, T.untyped])
  @built_on = T.let(nil, T.nilable(T::Hash[String, T.untyped]))
  @runtime_dependencies = T.let(nil, RuntimeDependencies)

  attributes.each do |key, value|
    case key.to_sym
    when :installed_as_dependency
      @installed_as_dependency = value.nil? ? false : value
    when :installed_on_request
      @installed_on_request = value.nil? ? false : value
      @installed_on_request_present = true
    when :changed_files
      @changed_files = T.let(value&.map { |f| Pathname(f) }, T.nilable(T::Array[Pathname]))
    else
      instance_variable_set(:"@#{key}", value)
    end
  end
end

Instance Attribute Details

#archString, ...

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:



52
53
54
# File 'tab.rb', line 52

def arch
  @arch
end

#built_onHash{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.

Returns:



58
59
60
# File 'tab.rb', line 58

def built_on
  @built_on
end

#homebrew_versionString?

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:



37
38
39
# File 'tab.rb', line 37

def homebrew_version
  @homebrew_version
end

#installed_as_dependencyBoolean

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 as a dependency.

Returns:

  • (Boolean)


28
29
30
# File 'tab.rb', line 28

def installed_as_dependency
  @installed_as_dependency
end

#installed_on_requestBoolean

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.

Returns:

  • (Boolean)


34
35
36
# File 'tab.rb', line 34

def installed_on_request
  @installed_on_request
end

#loaded_from_apiBoolean?

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:

  • (Boolean, nil)


43
44
45
# File 'tab.rb', line 43

def loaded_from_api
  @loaded_from_api
end

#loaded_from_internal_apiBoolean?

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:

  • (Boolean, nil)


46
47
48
# File 'tab.rb', line 46

def loaded_from_internal_api
  @loaded_from_internal_api
end

#runtime_dependenciesRuntimeDependencies

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.

Returns:



64
65
66
# File 'tab.rb', line 64

def runtime_dependencies
  @runtime_dependencies
end

#sourceHash{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.

Returns:



55
56
57
# File 'tab.rb', line 55

def source
  @source
end

#tabfilePathname?

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:



40
41
42
# File 'tab.rb', line 40

def tabfile
  @tabfile
end

#timeInteger?

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:



49
50
51
# File 'tab.rb', line 49

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.

Parameters:

Returns:

  • (T.attached_class)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'tab.rb', line 99

def self.create(formula_or_cask)
  attributes = {
    "homebrew_version"         => HOMEBREW_VERSION,
    "installed_as_dependency"  => false,
    "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,
  }

  new(attributes)
end

.emptyT.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.

Returns:

  • (T.attached_class)


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'tab.rb', line 145

def self.empty
  attributes = {
    "homebrew_version"         => HOMEBREW_VERSION,
    "installed_as_dependency"  => false,
    "installed_on_request"     => false,
    "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,
  }

  new(attributes)
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.

Note:

Results are cached.

Returns the Tab for a formula or cask install receipt at path.

Parameters:

Returns:

  • (T.attached_class)


122
123
124
125
126
127
128
129
# File 'tab.rb', line 122

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.

Parameters:

Returns:

  • (T.attached_class)


133
134
135
136
137
138
139
140
141
142
# File 'tab.rb', line 133

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)
end

Instance Method Details

#parsed_homebrew_versionVersion

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:



181
182
183
184
185
186
# File 'tab.rb', line 181

def parsed_homebrew_version
  homebrew_version = self.homebrew_version
  return Version::NULL if homebrew_version.nil?

  Version.new(homebrew_version)
end

#tapTap?

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:



189
190
191
192
# File 'tab.rb', line 189

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.

Parameters:



195
196
197
198
# File 'tab.rb', line 195

def tap=(tap)
  tap_name = tap.is_a?(Tap) ? tap.name : tap
  source["tap"] = tap_name
end

#writevoid

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.



201
202
203
204
# File 'tab.rb', line 201

def write
  self.class.cache[tabfile] = self
  T.must(tabfile).atomic_write(to_json)
end