Explain more Tab instantiation methods

This commit is contained in:
Alyssa Ross 2016-09-07 23:17:19 +01:00
parent d62029f899
commit 8c3a11bca8

View File

@ -46,10 +46,13 @@ class Tab < OpenStruct
new(attributes)
end
# Returns the Tab for an install receipt at `path`.
# Results are cached.
def self.from_file(path)
CACHE.fetch(path) { |p| CACHE[p] = from_file_content(File.read(p), p) }
end
# Like Tab.from_file, but bypass the cache.
def self.from_file_content(content, path)
attributes = Utils::JSON.load(content)
attributes["tabfile"] = path
@ -97,6 +100,8 @@ class Tab < OpenStruct
end
end
# Returns a tab for the named formula's installation,
# or a fake one if the formula is not installed.
def self.for_name(name)
for_formula(Formulary.factory(name))
end