Class: Bundler::Dependencies::Graph

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

Instance Method Summary collapse

Constructor Details

#initialize(lockfile: nil, specs: []) ⇒ Graph

Returns a new instance of Graph.



6
7
8
9
10
11
12
13
14
# File 'lib/bundler/dependencies/graph.rb', line 6

def initialize(lockfile: nil, specs: [])
  @lockfile = lockfile

  if lockfile
    load_lockfile
  else
    @specs = specs.compact
  end
end

Instance Method Details

#counts(min: 0) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/bundler/dependencies/graph.rb', line 33

def counts(min: 0)
  @counts ||= map do |gem|
    count = gem.dependency_count
    next if count < min

    [gem.name, gem.dependency_count]
  end.compact.sort_by(&:last).reverse.to_h
end

#delete(*specs) ⇒ Object



42
43
44
45
46
47
# File 'lib/bundler/dependencies/graph.rb', line 42

def delete(*specs)
  specs.each do |gem|
    spec = Spec.new(gem) unless gem.is_a?(Spec)
    gems.delete(spec)
  end
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/bundler/dependencies/graph.rb', line 25

def each(&block)
  gems.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bundler/dependencies/graph.rb', line 21

def empty?
  gems.empty?
end

#find(gem) ⇒ Object



29
30
31
# File 'lib/bundler/dependencies/graph.rb', line 29

def find(gem)
  include_dependency?(gem) ? Spec.find(gem) : nil
end

#include?(gem) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/bundler/dependencies/graph.rb', line 49

def include?(gem)
  gem = Spec.new(gem) unless gem.is_a?(Spec)
  gems.include?(gem)
end

#include_dependency?(gem) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/bundler/dependencies/graph.rb', line 54

def include_dependency?(gem)
  gem = Spec.new(gem) unless gem.is_a?(Spec)
  include?(gem) || any? { |spec| spec.include_dependency?(gem) }
end

#initialize_copy(source) ⇒ Object



16
17
18
19
# File 'lib/bundler/dependencies/graph.rb', line 16

def initialize_copy(source)
  super
  @gems = source.send(:gems).dup
end

#walk(&block) ⇒ Object



65
66
67
68
# File 'lib/bundler/dependencies/graph.rb', line 65

def walk(&block)
  Visitor.walk(self, &block)
  self
end

#without(*gems) ⇒ Object



59
60
61
62
63
# File 'lib/bundler/dependencies/graph.rb', line 59

def without(*gems)
  graph = dup
  graph.delete(*gems)
  graph.walk { |gem| gem.dependencies.delete(*gems) }
end