Class: Bundler::Index

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bundler/index.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Index) initialize



16
17
18
19
20
21
# 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

Instance Attribute Details

- (Object) sources (readonly)

Returns the value of attribute sources



13
14
15
# File 'lib/bundler/index.rb', line 13

def sources
  @sources
end

Class Method Details

+ (Object) build {|i| ... }

Yields:

  • (i)


7
8
9
10
11
# File 'lib/bundler/index.rb', line 7

def self.build
  i = new
  yield i
  i
end

Instance Method Details

- (Object) <<(spec)



90
91
92
93
94
95
96
97
98
99
# 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

- (Object) ==(o)



135
136
137
138
139
140
# 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

- (Object) add_source(index)



142
143
144
145
146
147
148
149
# 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

- (Object) each(&blk)



101
102
103
104
105
# File 'lib/bundler/index.rb', line 101

def each(&blk)
  specs.values.each do |specs|
    specs.each(&blk)
  end
end

- (Boolean) empty?



42
43
44
45
# File 'lib/bundler/index.rb', line 42

def empty?
  each { return false }
  true
end

- (Object) initialize_copy(o)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

- (Object) inspect



38
39
40
# 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

- (Object) local_search(query, base = nil)



74
75
76
77
78
79
80
81
82
# File 'lib/bundler/index.rb', line 74

def local_search(query, base = nil)
  case query
  when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query)
  when String then specs_by_name(query)
  when Gem::Dependency then search_by_dependency(query, base)
  else
    raise "You can't search for a #{query.inspect}."
  end
end

- (Object) search(query, base = nil) Also known as: []

Search this index's specs, and any source indexes that this index knows about, returning all of the results.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bundler/index.rb', line 57

def search(query, base = nil)
  results = local_search(query, base)
  seen = Set.new(results.map { |spec| [spec.name, spec.version, spec.platform] })

  @sources.each do |source|
    source.search(query, base).each do |spec|
      lookup = [spec.name, spec.version, spec.platform]
      unless seen.include?(lookup)
        results << spec
        seen << lookup
      end
    end
  end

  results.sort_by {|s| [s.version, s.platform.to_s == 'ruby' ? "\0" : s.platform.to_s] }
end

- (Object) search_all(name)



47
48
49
50
51
52
53
# 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

- (Object) size



129
130
131
132
133
# File 'lib/bundler/index.rb', line 129

def size
  @sources.inject(@specs.size) do |size, source|
    size += source.size
  end
end

- (Object) source_types



84
85
86
# File 'lib/bundler/index.rb', line 84

def source_types
  sources.map{|s| s.class }.uniq
end

- (Object) unmet_dependency_names

returns a list of the dependencies



108
109
110
111
112
113
114
# 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

- (Object) use(other, override_dupes = false)



116
117
118
119
120
121
122
123
124
125
126
127
# 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