Permalink
Browse files

add child sources to Index

  • Loading branch information...
1 parent 6e2ceab commit 84fdb604e1c9ecc630a03d981e102a075e1ee45c @indirect indirect committed May 18, 2011
Showing with 18 additions and 10 deletions.
  1. +3 −4 lib/bundler/definition.rb
  2. +15 −6 lib/bundler/index.rb
@@ -160,7 +160,7 @@ def resolve
def index
@index ||= Index.build do |idx|
@sources.each do |s|
- idx.use s.specs
+ idx.add_source s.specs
end
end
end
@@ -169,9 +169,8 @@ def index
# spec, even if (say) a git gem is not checked out.
def rubygems_index
@rubygems_index ||= Index.build do |idx|
- @sources.find_all{|s| s.is_a?(Source::Rubygems) }.each do |s|
- idx.use s.specs
- end
+ rubygems = @sources.find{|s| s.is_a?(Source::Rubygems) }
+ idx.add_source(rubygems)
end
end
View
@@ -33,7 +33,17 @@ def empty?
true
end
+ # Search this index's specs, and any source indexes that this index knows
+ # about, returning all of the results.
def search(query)
+ results = local_search(query)
+ @sources.each do |source|
+ results << source.search(query)
+ end
+ results
+ end
+
+ def local_search(query)
case query
when Gem::Specification, RemoteSpecification, LazySpecification then search_by_spec(query)
when String then specs_by_name(query)
@@ -69,12 +79,6 @@ def search_by_dependency(dependency, base = nil)
end
end
- def sources
- specs.values.map do |specs|
- specs.map{|s| s.source }
- end.flatten.uniq
- end
-
def source_types
sources.map{|s| s.class }.uniq
end
@@ -113,6 +117,11 @@ def ==(o)
end
end
+ def add_source(source)
+ raise ArgumentError, "Source must be an index, not #{source.class}" unless source.is_a?(Index)
+ @sources << source
+ end
+
private
def search_by_spec(spec)

0 comments on commit 84fdb60

Please sign in to comment.