aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-10 00:24:17 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-10 00:24:17 -0800
commit3e360694359c38fa343166a0e93db8aabfad9834 (patch)
tree8d9cfda1f224f88771d0421c230c20ee47d11486 /lib/bundler
parent028f2ecca4d9d71e83be4775e10389c888c188c1 (diff)
downloadbundler-3e360694359c38fa343166a0e93db8aabfad9834.tar.gz
Refactor indexes
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/definition.rb14
-rw-r--r--lib/bundler/environment.rb10
-rw-r--r--lib/bundler/index.rb39
-rw-r--r--lib/bundler/installer.rb46
-rw-r--r--lib/bundler/runtime.rb5
5 files changed, 64 insertions, 50 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 91e710bd..91d0c58d 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -32,20 +32,6 @@ module Bundler
@sources = sources
end
- def local_index
- @local_index ||= begin
- index = Index.new
-
- sources.each do |source|
- next unless source.respond_to?(:local_specs)
- index = source.local_specs.merge(index)
- end
-
- index = Index.from_installed_gems.merge(index)
- Index.from_cached_specs("#{Bundler.bundle_path}/cache").merge(index)
- end
- end
-
def groups
dependencies.map { |d| d.groups }.flatten.uniq
end
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index 92bdcf97..fbc6806a 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -11,6 +11,16 @@ module Bundler
private
+ def runtime_gems
+ @runtime_gems ||= Index.build do |i|
+ sources.each do |s|
+ i.use s.local_specs if s.respond_to?(:local_specs)
+ end
+
+ i.use Index.installed_gems
+ end
+ end
+
def group_specs(specs)
dependencies.each do |d|
spec = specs.find { |s| s.name == d.name }
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index 50a737f0..9b299843 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -1,9 +1,37 @@
module Bundler
class Index
+ def self.build
+ i = new
+ yield i
+ i
+ end
+
def self.from_installed_gems
Source::SystemGems.new.specs
end
+ def self.installed_gems
+ from_installed_gems
+ end
+
+ def self.cached_gems
+ build do |idx|
+ idx.use application_cached_gems
+ idx.use system_cached_gems
+ end
+ end
+
+ def self.application_cached_gems
+ path = "#{Bundler.root}/vendor/cache"
+ if File.directory?(path)
+ from_cached_specs(path)
+ end
+ end
+
+ def self.system_cached_gems
+ from_cached_specs("#{Bundler.bundle_path}/cache")
+ end
+
def self.from_cached_specs(path)
Source::GemCache.new("path" => path).specs
end
@@ -52,6 +80,15 @@ module Bundler
end
end
+ def use(other)
+ return unless other
+ other.each do |s|
+ next if search_by_spec(s).any?
+ @specs[s.name] << s
+ end
+ self
+ end
+
def merge!(other)
other.each do |spec|
self << spec
@@ -73,7 +110,7 @@ module Bundler
private
def search_by_spec(spec)
- @specs[spec.name].select { |s| s.version == spec.version }
+ @specs[spec.name].select { |s| s.version == spec.version && s.platform == spec.platform }
end
def search_by_dependency(dependency)
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 2638dadc..516ea025 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -91,51 +91,29 @@ module Bundler
end
def index
- @index ||= begin
- index = Index.new
+ @index ||= Index.build do |idx|
+ rubygems, other = sources.partition { |s| Source::Rubygems === s }
- rg_sources = sources.select { |s| s.is_a?(Source::Rubygems) }
- other_sources = sources.select { |s| !s.is_a?(Source::Rubygems) }
-
- other_sources.each do |source|
- i = source.specs
+ other.each do |source|
Bundler.ui.debug "Source: Processing index"
- index = i.merge(index)
+ idx.use source.specs
end
- index = Index.from_installed_gems.merge(index)
- index = Index.from_cached_specs("#{Bundler.bundle_path}/cache").merge(index)
-
- if File.directory?("#{root}/vendor/cache")
- index = cache_source.specs.merge(index)
- end
+ idx.use Index.installed_gems
+ idx.use Index.cached_gems
- rg_sources.each do |source|
- i = source.specs
+ rubygems.each do |source|
Bundler.ui.debug "Source: Processing index"
- index = i.merge(index)
+ idx.use source.specs
end
-
- index
end
end
def local_index
- @local_index ||= begin
- index = Index.new
-
- sources.each do |source|
- next unless source.respond_to?(:local_specs)
- index = source.local_specs.merge(index)
- end
-
- index = Index.from_installed_gems.merge(index)
-
- if File.directory?("#{root}/vendor/cache")
- index = cache_source.specs.merge(index).freeze
- end
-
- Index.from_cached_specs("#{Bundler.bundle_path}/cache").merge(index)
+ @local_index ||= Index.build do |idx|
+ idx.use runtime_gems
+ idx.use Index.application_cached_gems # vendor/cache
+ idx.use Index.system_cached_gems # $GEM_HOME/cache
end
end
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index d4330774..6d3f5ca8 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -97,7 +97,10 @@ module Bundler
alias gems specs
def index
- @definition.local_index
+ @index ||= Index.build do |idx|
+ idx.use runtime_gems
+ idx.use Index.system_cached_gems
+ end
end
def cache