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
def cleanup_cellar
return unless HOMEBREW_CELLAR.directory?
HOMEBREW_CELLAR.subdirs.each do |rack|
Formula.racks.each do |rack|
begin
cleanup_formula Formulary.from_rack(rack)
rescue FormulaUnavailableError, TapFormulaAmbiguityError

View File

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

View File

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

View File

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

View File

@ -809,18 +809,23 @@ class Formula
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}
def self.installed
@installed ||= if HOMEBREW_CELLAR.directory?
HOMEBREW_CELLAR.subdirs.map do |rack|
@installed ||= racks.map do |rack|
begin
Formulary.from_rack(rack)
rescue FormulaUnavailableError, TapFormulaAmbiguityError
end
end.compact
else
[]
end
end
def self.aliases