class Bundler::Index

Attributes

all_specs[R]
sources[R]
specs[R]

Public Class Methods

build() { |i| ... } click to toggle source
# File lib/bundler/index.rb, line 7
def self.build
  i = new
  yield i
  i
end
new() click to toggle source
# File lib/bundler/index.rb, line 16
def initialize
  @sources = []
  @cache = {}
  @specs = Hash.new { |h,k| h[k] = [] }
  @all_specs = Hash.new { |h,k| h[k] = [] }
end

Public Instance Methods

<<(spec) click to toggle source
# File lib/bundler/index.rb, line 90
def <<(spec)
  arr = specs_by_name(spec.name)

  arr.delete_if do |s|
    same_version?(s.version, spec.version) && s.platform == spec.platform
  end

  arr << spec
  spec
end
==(o) click to toggle source
# File lib/bundler/index.rb, line 135
def ==(o)
  all? do |spec|
    other_spec = o[spec].first
    (spec.dependencies & other_spec.dependencies).empty? && spec.source == other_spec.source
  end
end
[](query, base = nil)
Alias for: search
add_source(index) click to toggle source
# File lib/bundler/index.rb, line 142
def add_source(index)
  if index.is_a?(Index)
    @sources << index
    @sources.uniq! # need to use uniq! here instead of checking for the item before adding
  else
    raise ArgumentError, "Source must be an index, not #{index.class}"
  end
end
each(&blk) click to toggle source
# File lib/bundler/index.rb, line 101
def each(&blk)
  specs.values.each do |specs|
    specs.each(&blk)
  end
end
empty?() click to toggle source
# File lib/bundler/index.rb, line 42
def empty?
  each { return false }
  true
end
initialize_copy(o) click to toggle source
Calls superclass method
# File lib/bundler/index.rb, line 23
def initialize_copy(o)
  super
  @sources = @sources.dup
  @cache = {}
  @specs = Hash.new { |h,k| h[k] = [] }
  @all_specs = Hash.new { |h,k| h[k] = [] }

  o.specs.each do |name, array|
    @specs[name] = array.dup
  end
  o.all_specs.each do |name, array|
    @all_specs[name] = array.dup
  end
end
inspect() click to toggle source
# File lib/bundler/index.rb, line 38
def inspect
  "#<#{self.class}:0x#{object_id} sources=#{sources.map{|s| s.inspect}} specs.size=#{specs.size}>"
end
search_all(name) click to toggle source
# File lib/bundler/index.rb, line 47
def search_all(name)
  all_matches = @all_specs[name] + local_search(name)
  @sources.each do |source|
    all_matches.concat(source.search_all(name))
  end
  all_matches
end
size() click to toggle source
# File lib/bundler/index.rb, line 129
def size
  @sources.inject(@specs.size) do |size, source|
    size += source.size
  end
end
source_types() click to toggle source
# File lib/bundler/index.rb, line 84
def source_types
  sources.map{|s| s.class }.uniq
end
unmet_dependency_names() click to toggle source

returns a list of the dependencies

# File lib/bundler/index.rb, line 108
def unmet_dependency_names
  names = []
  each{|s| names.push(*s.dependencies.map{|d| d.name }) }
  names.uniq!
  names.delete_if{|n| n == "bundler" }
  names.select{|n| search(n).empty? }
end
use(other, override_dupes = false) click to toggle source
# File lib/bundler/index.rb, line 116
def use(other, override_dupes = false)
  return unless other
  other.each do |s|
    if (dupes = search_by_spec(s)) && dupes.any?
      @all_specs[s.name] = [s] + dupes
      next unless override_dupes
      @specs[s.name] -= dupes
    end
    @specs[s.name] << s
  end
  self
end

Private Instance Methods

same_version?(a, b) click to toggle source
# File lib/bundler/index.rb, line 187
def same_version?(a, b)
  regex = /^(.*?)(?:\.0)*$/
  a.to_s[regex, 1] == b.to_s[regex, 1]
end
search_by_dependency(dependency, base = nil) click to toggle source
# File lib/bundler/index.rb, line 157
def search_by_dependency(dependency, base = nil)
  @cache[base || false] ||= {}
  @cache[base || false][dependency] ||= begin
    specs = specs_by_name(dependency.name) + (base || [])
    found = specs.select do |spec|
      if base # allow all platforms when searching from a lockfile
        dependency.matches_spec?(spec)
      else
        dependency.matches_spec?(spec) && Gem::Platform.match(spec.platform)
      end
    end

    wants_prerelease = dependency.requirement.prerelease?
    only_prerelease  = specs.all? {|spec| spec.version.prerelease? }

    unless wants_prerelease || only_prerelease
      found.reject! { |spec| spec.version.prerelease? }
    end

    found
  end
end
search_by_spec(spec) click to toggle source
# File lib/bundler/index.rb, line 180
def search_by_spec(spec)
  specs_by_name(spec.name).select do |s|
    same_version?(s.version, spec.version) && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform)
  end
end
spec_satisfies_dependency?(spec, dep) click to toggle source
# File lib/bundler/index.rb, line 197
def spec_satisfies_dependency?(spec, dep)
  return false unless dep.name == spec.name
  dep.requirement.satisfied_by?(spec.version)
end
specs_by_name(name) click to toggle source
# File lib/bundler/index.rb, line 153
def specs_by_name(name)
  @specs[name]
end