summaryrefslogtreecommitdiff
path: root/lib/bundler/index.rb
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/index.rb
parent028f2ecca4d9d71e83be4775e10389c888c188c1 (diff)
downloadbundler-3e360694359c38fa343166a0e93db8aabfad9834.tar.gz
Refactor indexes
Diffstat (limited to 'lib/bundler/index.rb')
-rw-r--r--lib/bundler/index.rb39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index 50a737f063..9b2998435d 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)