Class: Berkshelf::Resolver::Graph

Inherits:
Solve::Graph
  • Object
show all
Defined in:
lib/berkshelf/resolver/graph.rb

Instance Method Summary collapse

Instance Method Details

#populate(sources) ⇒ Object

Parameters:


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/berkshelf/resolver/graph.rb', line 35

def populate(sources)
  universe(sources).each do |cookbook|
    next if has_artifact?(cookbook.name, cookbook.version)

    artifact(cookbook.name, cookbook.version)

    cookbook.dependencies.each do |dependency, constraint|
      constraint = nil if constraint.empty?
      artifact(cookbook.name, cookbook.version).depends(dependency, constraint)
    end
  end
end

#populate_local(cookbook) ⇒ Hash

Add dependencies of a locally cached cookbook to the graph

Parameters:

Returns:

  • (Hash)

23
24
25
26
27
28
29
30
31
32
# File 'lib/berkshelf/resolver/graph.rb', line 23

def populate_local(cookbook)
  name    = cookbook.cookbook_name
  version = cookbook.version

  artifact(name, version)
  cookbook.dependencies.each do |dependency, constraint|
    constraint = nil if constraint.empty?
    artifact(name, version).depends(dependency, constraint)
  end
end

#populate_store(store = nil) ⇒ Object

Parameters:


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/berkshelf/resolver/graph.rb', line 5

def populate_store(store = nil)
  store ||= Berkshelf::CookbookStore.instance

  store.cookbooks.each do |cookbook|
    artifact(cookbook.cookbook_name, cookbook.version)

    cookbook.dependencies.each do |dependency, constraint|
      constraint = nil if constraint.empty?
      artifact(cookbook.cookbook_name, cookbook.version).depends(dependency, constraint)
    end
  end
end

#universe(sources) ⇒ Array<Berkshelf::RemoteCookbook>

Parameters:

Returns:

  • (Array<Berkshelf::RemoteCookbook>)

51
52
53
54
55
# File 'lib/berkshelf/resolver/graph.rb', line 51

def universe(sources)
  cookbooks = []
  Array(sources).each { |source| cookbooks = cookbooks | source.universe }
  cookbooks
end