From 9274f7cda1e2261e581979887ca15ba41fef6bd9 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 21 Aug 2012 11:39:45 -0400 Subject: [PATCH] Formula.Enumerable Deprecated Formula.all, replaced usage with more appropriate enumerable options. Just check out how much nicer `brew audit` runs now. --- Library/Contributions/cmds/brew-leaves.rb | 2 +- Library/Contributions/cmds/brew-server | 4 +-- Library/Homebrew/cmd/audit.rb | 2 +- Library/Homebrew/cmd/doctor.rb | 2 +- Library/Homebrew/cmd/options.rb | 4 +-- Library/Homebrew/cmd/uses.rb | 2 +- Library/Homebrew/formula.rb | 31 +++++++++-------------- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Library/Contributions/cmds/brew-leaves.rb b/Library/Contributions/cmds/brew-leaves.rb index d2cc2a3ae0..068fb21dfa 100755 --- a/Library/Contributions/cmds/brew-leaves.rb +++ b/Library/Contributions/cmds/brew-leaves.rb @@ -6,7 +6,7 @@ require 'formula' def get_used_by used_by = {} - Formula.all.each do |f| + Formula.each do |f| next if f.deps == nil f.deps.each do |dep| diff --git a/Library/Contributions/cmds/brew-server b/Library/Contributions/cmds/brew-server index fe81ea64c6..435a4abfa3 100755 --- a/Library/Contributions/cmds/brew-server +++ b/Library/Contributions/cmds/brew-server @@ -151,7 +151,7 @@ get '/formula/:name' do end end - used_by = Formula.all.select{|ff| ff.deps.include?(klass.name)}.map{|f| f.name}.flatten.uniq.sort + used_by = Formula.select{|ff| ff.deps.include?(klass.name)}.map{|f| f.name}.flatten.uniq.sort unless used_by.empty? s << <<-HTML
Used by @@ -174,7 +174,7 @@ end def installed_formulas - Formula.all.select{|formula| formula.installed?} + Formula.select{|formula| formula.installed?} end get '/installed' do diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index 0494f4c3f9..6e3dce11e2 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -8,7 +8,7 @@ module Homebrew extend self problem_count = 0 ff = if ARGV.named.empty? - Formula.all + Formula else ARGV.formulae end diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index ad72a6dfc8..a6cedd2ffd 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -707,7 +707,7 @@ def check_for_linked_keg_only_brews warnings = Hash.new - Formula.all.each do |f| + Formula.each do |f| next unless f.keg_only? and f.installed? links = __check_linked_brew f warnings[f.name] = links unless links.empty? diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index 2f64f5b393..9cb41f7bb5 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -3,11 +3,11 @@ require 'cmd/outdated' def ff if ARGV.include? "--all" - Formula.all + Formula elsif ARGV.include? "--installed" # outdated brews count as installed outdated = Homebrew.outdated_brews.collect{ |b| b.name } - Formula.all.select do |f| + Formula.select do |f| f.installed? or outdated.include? f.name end else diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 6c5886a8c2..fc463c6f35 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -9,7 +9,7 @@ module Homebrew extend self def uses raise FormulaUnspecifiedError if ARGV.named.empty? - uses = Formula.all.select do |f| + uses = Formula.select do |f| ARGV.formulae.all? do |ff| if ARGV.flag? '--recursive' f.recursive_deps.include? ff diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 773b6d7462..f9b5a112c2 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -289,30 +289,23 @@ class Formula Dir["#{HOMEBREW_REPOSITORY}/Library/Formula/*.rb"].map{ |f| File.basename f, '.rb' }.sort end - # an array of all Formula, instantiated - def self.all - map{ |f| f } - end - def self.map - rv = [] - each{ |f| rv << yield(f) } - rv - end def self.each - names.each do |n| - begin - yield Formula.factory(n) - rescue + names.each do |name| + yield begin + Formula.factory(name) + rescue => e # Don't let one broken formula break commands. But do complain. - onoe "Formula #{n} will not import." + onoe "Failed to import: #{name}" + next end end end - - def self.select - ff = [] - each{ |f| ff << f if yield(f) } - ff + class << self + include Enumerable + end + def self.all + opoo "Formula.all is deprecated, simply use Formula.map" + map end def self.installed