123456789_123456789_123456789_123456789_123456789_

Class: Bundler::Resolver::Base

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/resolver/base.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source_requirements, dependencies, base, platforms, options) ⇒ Base

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 10

def initialize(source_requirements, dependencies, base, platforms, options)
  @source_requirements = source_requirements

  @base = base

  @packages = Hash.new do |hash, name|
    hash[name] = Package.new(name, platforms, **options)
  end

  @requirements = dependencies.map do |dep|
    dep_platforms = dep.gem_platforms(platforms)

    # Dependencies scoped to external platforms are ignored
    next if dep_platforms.empty?

    name = dep.name

    @packages[name] = Package.new(name, dep_platforms, **options.merge(dependency: dep))

    dep
  end.compact
end

Instance Attribute Details

#packages (readonly)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 8

attr_reader :packages, :requirements, :source_requirements

#requirements (readonly)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 8

attr_reader :packages, :requirements, :source_requirements

#source_requirements (readonly)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 8

attr_reader :packages, :requirements, :source_requirements

Instance Method Details

#[](name)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 37

def [](name)
  @base[name]
end

#base_requirements

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 49

def base_requirements
  @base_requirements ||= build_base_requirements
end

#build_base_requirements (private)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 107

def build_base_requirements
  base_requirements = {}
  @base.each do |ls|
    req = Gem::Requirement.new(ls.version)
    base_requirements[ls.name] = req
  end
  base_requirements
end

#delete(specs)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 41

def delete(specs)
  @base.delete(specs)
end

#get_package(name)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 45

def get_package(name)
  @packages[name]
end

#include_prereleases(names)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 69

def include_prereleases(names)
  names.each do |name|
    get_package(name).consider_prereleases!
  end
end

#include_remote_specs(names)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 75

def include_remote_specs(names)
  names.each do |name|
    get_package(name).consider_remote_versions!
  end
end

#indirect_pins(names) (private)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 83

def indirect_pins(names)
  names.select {|name| @base_requirements[name].exact? && @requirements.none? {|dep| dep.name == name } }
end

#loosen_names(names) (private)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 91

def loosen_names(names)
  names.each do |name|
    version = @base_requirements[name].requirements.first[1]

    @base_requirements[name] = Gem::Requirement.new(">= #{version}")

    @base.delete_by_name(name)
  end
end

#pins(names) (private)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 87

def pins(names)
  names.select {|name| @base_requirements[name].exact? }
end

#specs_compatible_with(result)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 33

def specs_compatible_with(result)
  @base.specs_compatible_with(result)
end

#unlock_names(names)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 53

def unlock_names(names)
  indirect_pins = indirect_pins(names)

  if indirect_pins.any?
    loosen_names(indirect_pins)
  else
    pins = pins(names)

    if pins.any?
      loosen_names(pins)
    else
      unrestrict_names(names)
    end
  end
end

#unrestrict_names(names) (private)

[ GitHub ]

  
# File 'lib/bundler/resolver/base.rb', line 101

def unrestrict_names(names)
  names.each do |name|
    @base_requirements.delete(name)
  end
end