class Bundler::Index

Constants

NULL
RUBY

Attributes

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

Public Class Methods

build() { |i| ... } click to toggle source
# File lib/bundler/index.rb, line 8
def self.build
  i = new
  yield i
  i
end
new() click to toggle source
# File lib/bundler/index.rb, line 20
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 91
def <<(spec)
  @specs[spec.name]["#{spec.version}-#{spec.platform}"] = spec

  spec
end
==(other) click to toggle source
# File lib/bundler/index.rb, line 135
def ==(other)
  all? do |spec|
    other_spec = other[spec].first
    other_spec && (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)
  raise ArgumentError, "Source must be an index, not #{index.class}" unless index.is_a?(Index)
  @sources << index
  @sources.uniq! # need to use uniq! here instead of checking for the item before adding
end
dependency_names() click to toggle source
# File lib/bundler/index.rb, line 110
def dependency_names
  names = []
  each {|s| names.push(*s.dependencies.map(&:name)) }
  names.uniq
end
each(&blk) click to toggle source
# File lib/bundler/index.rb, line 97
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 46
def empty?
  each { return false }
  true
end
initialize_copy(o) click to toggle source
Calls superclass method
# File lib/bundler/index.rb, line 27
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, 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 42
def inspect
  "#<#{self.class}:0x#{object_id} sources=#{sources.map(&:inspect)} specs.size=#{specs.size}>"
end
search_all(name) click to toggle source
# File lib/bundler/index.rb, line 51
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
unmet_dependency_names() click to toggle source

returns a list of the dependencies

# File lib/bundler/index.rb, line 104
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 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
      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 183
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 154
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 177
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 193
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 150
def specs_by_name(name)
  @specs[name].values
end