aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dependency.rb
diff options
context:
space:
mode:
authorJack Nagel2013-05-10 23:45:05 -0500
committerJack Nagel2013-05-10 23:45:05 -0500
commit12f4ccd7f350cab238dab88a7a6a1a7d55455185 (patch)
tree3b6ee456ebb396f1391634157b1e01619fd3a1cc /Library/Homebrew/dependency.rb
parent3be67f72523b55486cad2bd2fa0f6c79b23c82a4 (diff)
downloadbrew-12f4ccd7f350cab238dab88a7a6a1a7d55455185.tar.bz2
Refactor Dependency.expand
Diffstat (limited to 'Library/Homebrew/dependency.rb')
-rw-r--r--Library/Homebrew/dependency.rb42
1 files changed, 24 insertions, 18 deletions
diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb
index 6c78e10ac..d87d74ccf 100644
--- a/Library/Homebrew/dependency.rb
+++ b/Library/Homebrew/dependency.rb
@@ -54,29 +54,35 @@ class Dependency
tags << 'universal' if to_formula.build.has_option? 'universal'
end
- # Expand the dependencies of dependent recursively, optionally yielding
- # [dependent, dep] pairs to allow callers to apply arbitrary filters to
- # the list.
- # The default filter, which is applied when a block is not given, omits
- # optionals and recommendeds based on what the dependent has asked for.
- def self.expand(dependent, &block)
- dependent.deps.map do |dep|
- prune = catch(:prune) do
+ class << self
+ # Expand the dependencies of dependent recursively, optionally yielding
+ # [dependent, dep] pairs to allow callers to apply arbitrary filters to
+ # the list.
+ # The default filter, which is applied when a block is not given, omits
+ # optionals and recommendeds based on what the dependent has asked for.
+ def expand(dependent, &block)
+ dependent.deps.map do |dep|
+ if prune?(dependent, dep, &block)
+ next
+ else
+ expand(dep.to_formula, &block) << dep
+ end
+ end.flatten.compact.uniq
+ end
+
+ def prune?(dependent, dep, &block)
+ catch(:prune) do
if block_given?
yield dependent, dep
elsif dep.optional? || dep.recommended?
- Dependency.prune unless dependent.build.with?(dep.name)
+ prune unless dependent.build.with?(dep.name)
end
end
+ end
- next if prune
-
- expand(dep.to_formula, &block) << dep
- end.flatten.compact.uniq
- end
-
- # Used to prune dependencies when calling expand with a block.
- def self.prune
- throw(:prune, true)
+ # Used to prune dependencies when calling expand with a block.
+ def prune
+ throw(:prune, true)
+ end
end
end