lib/bundler/source.rb in bundler-1.0.0.beta.1 vs lib/bundler/source.rb in bundler-1.0.0.beta.2
- old
+ new
@@ -13,25 +13,22 @@
def initialize(options = {})
@options = options
@remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
@allow_remote = false
+ @allow_cached = false
# Hardcode the paths for now
- @installed = {}
@caches = [ Bundler.app_cache ] + Gem.path.map { |p| File.expand_path("#{p}/cache") }
@spec_fetch_map = {}
end
def remote!
@allow_remote = true
end
- def [](spec)
- installed_specs[spec].first ||
- @allow_remote && (
- cached_specs[spec].first ||
- remote_specs[spec].first)
+ def cached!
+ @allow_cached = true
end
def hash
Rubygems.hash
end
@@ -68,28 +65,28 @@
remotes = self.remotes.map { |r| r.to_s }.join(', ')
"rubygems repository #{remotes}"
end
def specs
- @specs ||= @allow_remote ? fetch_specs : installed_specs
+ @specs ||= fetch_specs
end
def fetch(spec)
action = @spec_fetch_map[spec.full_name]
action.call if action
end
def install(spec)
path = cached_gem(spec)
- if @installed[spec.full_name]
+ if installed_specs[spec].any?
Bundler.ui.info "Using #{spec.name} (#{spec.version}) "
return
- else
- Bundler.ui.info "Installing #{spec.name} (#{spec.version}) "
end
+ Bundler.ui.info "Installing #{spec.name} (#{spec.version}) "
+
install_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir
installer = Gem::Installer.new path,
:install_dir => install_path,
:ignore_dependencies => true,
:wrappers => true,
@@ -139,32 +136,43 @@
end
def fetch_specs
Index.build do |idx|
idx.use installed_specs
- idx.use cached_specs
- idx.use remote_specs
+ idx.use cached_specs if @allow_cached
+ idx.use remote_specs if @allow_remote
end
end
def installed_specs
@installed_specs ||= begin
idx = Index.new
Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |name, spec|
- @installed[spec.full_name] = true
+ next if name == 'bundler'
spec.source = self
idx << spec
end
+ # Always have bundler locally
+ bundler = Gem::Specification.new do |s|
+ s.name = 'bundler'
+ s.version = VERSION
+ s.platform = Gem::Platform::RUBY
+ s.source = self
+ # TODO: Remove this
+ s.loaded_from = 'w0t'
+ end
+ idx << bundler
idx
end
end
def cached_specs
@cached_specs ||= begin
idx = Index.new
@caches.each do |path|
Dir["#{path}/*.gem"].each do |gemfile|
+ next if name == 'bundler'
s = Gem::Format.from_file_by_path(gemfile).spec
s.source = self
idx << s
end
end
@@ -181,10 +189,11 @@
remotes.each do |uri|
Bundler.ui.info "Fetching source index for #{uri}"
Gem.sources = ["#{uri}"]
fetch_all_remote_specs do |n,v|
v.each do |name, version, platform|
+ next if name == 'bundler'
spec = RemoteSpecification.new(name, version, platform, uri)
spec.source = self
# Temporary hack until this can be figured out better
@spec_fetch_map[spec.full_name] = lambda do
path = download_gem_from_uri(spec, uri)
@@ -235,18 +244,19 @@
end
class Path
attr_reader :path, :options
# Kind of a hack, but needed for the lock file parser
- attr_accessor :name, :version
+ attr_accessor :version
DEFAULT_GLOB = "{,*/}*.gemspec"
def initialize(options)
@options = options
@glob = options["glob"] || DEFAULT_GLOB
+ @allow_cached = false
@allow_remote = false
if options["path"]
@path = Pathname.new(options["path"]).expand_path(Bundler.root)
end
@@ -257,10 +267,14 @@
def remote!
@allow_remote = true
end
+ def cached!
+ @allow_cached = true
+ end
+
def self.from_lock(options)
new(options.merge("path" => options.delete("remote")))
end
def to_lock
@@ -338,14 +352,10 @@
end
index
end
- def [](spec)
- specs[spec].first
- end
-
def local_specs
@local_specs ||= load_spec_files
end
class Installer < Gem::Installer
@@ -482,12 +492,13 @@
def unlock!
@revision = nil
end
+ # TODO: actually cache git specs
def specs
- if @allow_remote && !@update
+ if (@allow_remote || @allow_cached) && !@update
# Start by making sure the git cache is up to date
cache
checkout
@update = true
end
@@ -504,10 +515,10 @@
end
generate_bin(spec)
end
def load_spec_files
- super
+ super if cache_path.exist?
rescue PathError
raise PathError, "#{to_s} is not checked out. Please run `bundle install`"
end
private