Class: Terraspace::Builder::Children

Inherits:
Object
  • Object
show all
Includes:
Util::Logging
Defined in:
lib/terraspace/builder/children.rb

Instance Method Summary collapse

Methods included from Util::Logging

#logger

Constructor Details

#initialize(mod, options = {}) ⇒ Children

Returns a new instance of Children.



5
6
7
8
# File 'lib/terraspace/builder/children.rb', line 5

def initialize(mod, options={})
  @mod, @options = mod, options
  @queue = []
end

Instance Method Details

#buildObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/terraspace/builder/children.rb', line 10

def build
  # Find out if current deploy stack contains dependency
  dependencies = Terraspace::Dependency::Registry.data
  root = dependencies.find do |parent_child|
    parent, _ = parent_child.split(':')
    parent == @mod.name
  end
  return unless root

  # Go down dependency graph to build a queue for processing
  name, _ = root.split(':')
  node = Terraspace::Dependency::Node.find_by(name: name)
  build_queue(node)
  logger.debug "Terraspace::Builder::Children @queue #{@queue}"

  # Process queue in reverse order to build leaf nodes first
  @queue.reverse.each do |node|
    mod = Terraspace::Mod.new(node.name, @options)
    Terraspace::Compiler::Perform.new(mod).compile
  end
end

#build_queue(node) ⇒ Object

Use depth first traversal to build queue



33
34
35
36
37
38
39
# File 'lib/terraspace/builder/children.rb', line 33

def build_queue(node)
  node.children.each do |child|
    @queue << child
    build_queue(child)
  end
  @queue
end