add Formula.racks

Also exclude symlink when enumerating installed racks.
This commit is contained in:
Xu Cheng 2015-08-13 20:35:22 +08:00
parent c7a484824c
commit 203cecb463
5 changed files with 19 additions and 15 deletions

View File

@ -31,8 +31,7 @@ module Homebrew
end end
def cleanup_cellar def cleanup_cellar
return unless HOMEBREW_CELLAR.directory? Formula.racks.each do |rack|
HOMEBREW_CELLAR.subdirs.each do |rack|
begin begin
cleanup_formula Formulary.from_rack(rack) cleanup_formula Formulary.from_rack(rack)
rescue FormulaUnavailableError, TapFormulaAmbiguityError rescue FormulaUnavailableError, TapFormulaAmbiguityError

View File

@ -22,7 +22,7 @@ module Homebrew
def print_info def print_info
if ARGV.named.empty? if ARGV.named.empty?
if HOMEBREW_CELLAR.exist? if HOMEBREW_CELLAR.exist?
count = HOMEBREW_CELLAR.subdirs.length count = Formula.racks.length
puts "#{count} keg#{plural(count)}, #{HOMEBREW_CELLAR.abv}" puts "#{count} keg#{plural(count)}, #{HOMEBREW_CELLAR.abv}"
end end
else else

View File

@ -1,5 +1,6 @@
# Links any Applications (.app) found in installed prefixes to /Applications # Links any Applications (.app) found in installed prefixes to /Applications
require "keg" require "keg"
require "formula"
module Homebrew module Homebrew
def linkapps def linkapps
@ -12,8 +13,7 @@ module Homebrew
end end
if ARGV.named.empty? if ARGV.named.empty?
racks = HOMEBREW_CELLAR.subdirs kegs = Formula.racks.map do |rack|
kegs = racks.map do |rack|
keg = rack.subdirs.map { |d| Keg.new(d) } keg = rack.subdirs.map { |d| Keg.new(d) }
next if keg.empty? next if keg.empty?
keg.detect(&:linked?) || keg.max { |a, b| a.version <=> b.version } keg.detect(&:linked?) || keg.max { |a, b| a.version <=> b.version }

View File

@ -78,7 +78,7 @@ module Homebrew
def filtered_list def filtered_list
names = if ARGV.named.empty? names = if ARGV.named.empty?
HOMEBREW_CELLAR.subdirs Formula.racks
else else
ARGV.named.map { |n| HOMEBREW_CELLAR+n }.select(&:exist?) ARGV.named.map { |n| HOMEBREW_CELLAR+n }.select(&:exist?)
end end

View File

@ -809,18 +809,23 @@ class Formula
end end
end end
# An array of all racks currently installed.
def self.racks
@racks ||= if HOMEBREW_CELLAR.directory?
HOMEBREW_CELLAR.subdirs.reject(&:symlink?)
else
[]
end
end
# An array of all installed {Formula} # An array of all installed {Formula}
def self.installed def self.installed
@installed ||= if HOMEBREW_CELLAR.directory? @installed ||= racks.map do |rack|
HOMEBREW_CELLAR.subdirs.map do |rack|
begin begin
Formulary.from_rack(rack) Formulary.from_rack(rack)
rescue FormulaUnavailableError, TapFormulaAmbiguityError rescue FormulaUnavailableError, TapFormulaAmbiguityError
end end
end.compact end.compact
else
[]
end
end end
def self.aliases def self.aliases