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] = Hash.new }
  @all_specs = Hash.new { |h,k| h[k] = [] }
end

Public Instance Methods

<<(spec) click to toggle source
# File lib/bundler/index.rb, line 86
def <<(spec)
  @specs[spec.name]["#{spec.version}-#{spec.platform}"] = spec

  spec
end
==(o) click to toggle source
# File lib/bundler/index.rb, line 130
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 137
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
dependency_names() click to toggle source
# File lib/bundler/index.rb, line 105
def dependency_names
  names = []
  each{|s| names.push(*s.dependencies.map{|d| d.name }) }
  names.uniq
end
each(&blk) click to toggle source
# File lib/bundler/index.rb, line 92
def each(&blk)
  specs.values.each do |spec_sets|
    spec_sets.values.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] = Hash.new }
  @all_specs = Hash.new { |h,k| h[k] = [] }

  o.specs.each do |name, hash|
    @specs[name] = hash.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 124
def size
  @sources.inject(@specs.size) do |size, source|
    size += source.size
  end
end
unmet_dependency_names() click to toggle source

returns a list of the dependencies

# File lib/bundler/index.rb, line 99
def unmet_dependency_names
  names = dependency_names
  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 111
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
      self << s
    end
    self << s
  end
  self
end

Private Instance Methods

same_version?(a, b) click to toggle source
# File lib/bundler/index.rb, line 181
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 152
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 175
def search_by_spec(spec)
  spec = @specs[spec.name]["#{spec.version}-#{spec.platform}"]
  spec ? [spec] : []
end
spec_satisfies_dependency?(spec, dep) click to toggle source
# File lib/bundler/index.rb, line 191
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 148
def specs_by_name(name)
  @specs[name].values
end