Sha256: e0d26ce70434c2ee9741b28f2f5b3f4ddf36ac08a9685956b50598dd0eeaaa53

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

class Terraspace::Builder
  class Children
    include Terraspace::Util::Logging

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

    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

    # Use depth first traversal to build queue
    def build_queue(node)
      node.children.each do |child|
        @queue << child
        build_queue(child)
      end
      @queue
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
terraspace-2.1.5 lib/terraspace/builder/children.rb
terraspace-2.1.4 lib/terraspace/builder/children.rb
terraspace-2.1.3 lib/terraspace/builder/children.rb
terraspace-2.1.2 lib/terraspace/builder/children.rb
terraspace-2.1.1 lib/terraspace/builder/children.rb
terraspace-2.1.0 lib/terraspace/builder/children.rb
terraspace-2.0.3 lib/terraspace/builder/children.rb
terraspace-2.0.2 lib/terraspace/builder/children.rb
terraspace-2.0.1 lib/terraspace/builder/children.rb
terraspace-2.0.0 lib/terraspace/builder/children.rb
terraspace-1.1.7 lib/terraspace/builder/children.rb