From dc1be896d8edb63cf1afd168a331a86b6fe2f289 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 1 Jan 2012 15:22:36 -0600 Subject: [PATCH] tab: allow retrieving tabs from arbitrary kegs This will be useful in places where we need information about things other than the currently linked keg, such as `brew info`. Signed-off-by: Jack Nagel --- Library/Homebrew/tab.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 9eb9a34a95..ec80b0204f 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -27,6 +27,16 @@ class Tab < OpenStruct return tab end + def self.for_keg keg + path = keg+'INSTALL_RECEIPT.json' + + if path.exist? + self.from_file path + else + self.dummy_tab Formula.factory(keg.parent.basename) + end + end + def self.for_formula f f = Formula.factory f unless f.kind_of? Formula path = HOMEBREW_REPOSITORY + 'Library' + 'LinkedKegs' + f.name + 'INSTALL_RECEIPT.json' @@ -42,11 +52,15 @@ class Tab < OpenStruct # TODO: # This isn't the best behavior---perhaps a future version of Homebrew can # treat missing Tabs as errors. - Tab.new :used_options => [], - :unused_options => f.options.map { |o, _| o} + self.dummy_tab f end end + def self.dummy_tab f + Tab.new :used_options => [], + :unused_options => f.options.map { |o, _| o} + end + def installed_with? opt used_options.include? opt end