Permalink
Browse files

Have Bundler::Dependency subclass Gem::Dependency

  • Loading branch information...
1 parent 9e97f13 commit 648ac7f4b4456608625334f5ac711d0f33dadc86 Carl Lerche committed Dec 16, 2009
Showing with 17 additions and 18 deletions.
  1. +1 −7 lib/bundler/bundle.rb
  2. +7 −9 lib/bundler/dependency.rb
  3. +8 −1 lib/bundler/resolver.rb
  4. +1 −1 spec/support/builders.rb
@@ -38,12 +38,6 @@ def install(options = {})
s.local = options[:cached]
end
- source_requirements = {}
- dependencies = dependencies.map do |dep|
- source_requirements[dep.name] = dep.source if dep.source
- dep.to_gem_dependency
- end
-
# Check to see whether the existing cache meets all the requirements
begin
valid = nil
@@ -57,7 +51,7 @@ def install(options = {})
# or the user passed --update
if update || !valid
Bundler.logger.info "Calculating dependencies..."
- bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements)
+ bundle = Resolver.resolve(dependencies, [@cache] + sources)
download(bundle, options)
do_install(bundle, options)
valid = bundle
@@ -1,7 +1,7 @@
module Bundler
class InvalidEnvironmentName < StandardError; end
- class Dependency
+ class Dependency < Gem::Dependency
attr_reader :name, :version, :require_as, :only, :except
attr_accessor :source
@@ -10,8 +10,8 @@ def initialize(name, options = {}, &block)
options[k.to_s] = v
end
- @name = name
- @version = options["version"] || ">= 0"
+ super(name, options["version"] || ">= 0")
+
@require_as = options["require_as"]
@only = options["only"]
@except = options["except"]
@@ -31,10 +31,6 @@ def in?(environment)
true
end
- def to_s
- to_gem_dependency.to_s
- end
-
def require_env(environment)
return unless in?(environment)
@@ -51,14 +47,16 @@ def require_env(environment)
@block.call if @block
end
- def to_gem_dependency
- @gem_dep ||= Gem::Dependency.new(name, version)
+ def no_bundle?
+ source == SystemGemSource.instance
end
def ==(o)
[name, version, require_as, only, except] ==
[o.name, o.version, o.require_as, o.only, o.except]
end
+ alias version version_requirements
+
end
end
@@ -36,7 +36,14 @@ class Resolver
# ==== Returns
# <GemBundle>,nil:: If the list of dependencies can be resolved, a
# collection of gemspecs is returned. Otherwise, nil is returned.
- def self.resolve(requirements, sources, source_requirements = {})
+ def self.resolve(requirements, sources)
+ source_requirements = {}
+
+ requirements.each do |r|
+ next unless r.source
+ source_requirements[r.name] = r.source
+ end
+
resolver = new(sources, source_requirements)
result = catch(:success) do
resolver.resolve(requirements, {})
@@ -124,7 +124,7 @@ def build_spec(name, version, &block)
end
def build_dep(name, requirements = Gem::Requirement.default, type = :runtime)
- Gem::Dependency.new(name, requirements, type)
+ Bundler::Dependency.new(name, :version => requirements)
end
def build_lib(name, *args, &blk)

0 comments on commit 648ac7f

Please sign in to comment.