class AwsCftTools::DependencyTree
Dependency Tree¶ ↑
Manage dependencies between CloudFormation templates based on exported and imported variables.
Attributes
filenames[R]
nodes[R]
variables[R]
Public Class Methods
new()
click to toggle source
# File lib/aws_cft_tools/dependency_tree.rb, line 17 def initialize @nodes = Nodes.new @variables = Variables.new @filenames = [] end
Public Instance Methods
closed_subset(set)
click to toggle source
finds a subset of the given set that has no dependencies outside the set
@param set [Array<T>] @return [Array<T>]
# File lib/aws_cft_tools/dependency_tree.rb, line 93 def closed_subset(set) # list all nodes that have no dependents outside the set close_subset(set, &method(:dependents_for)) end
linked(from, to)
click to toggle source
links two nodes in a directed fashion
The template named by from provides resources required by the template named by to.
@param from [#to_s] @param to [#to_s]
# File lib/aws_cft_tools/dependency_tree.rb, line 81 def linked(from, to) linker = "#{from}$$#{to}" provided(from, linker) required(to, linker) end
provided(filename, variable)
click to toggle source
notes that the given filename defines the given variable name
@param filename [#to_s] @param variable [String]
# File lib/aws_cft_tools/dependency_tree.rb, line 53 def provided(filename, variable) filename = filename.to_s nodes.make_link(variable, filename) @filenames |= [filename] exported(variable) end
required(filename, variable)
click to toggle source
notes that the given filename requires the given variable name to be defined before deployment
@param filename [#to_s] @param variable [String]
# File lib/aws_cft_tools/dependency_tree.rb, line 66 def required(filename, variable) filename = filename.to_s nodes.make_link(filename, variable) @filenames |= [filename] variables.referenced(variable) end
sort()
click to toggle source
computes a topological sort and returns the filenames in that sort order
@return [Array<String>]
# File lib/aws_cft_tools/dependency_tree.rb, line 43 def sort nodes.tsort & filenames end
Private Instance Methods
close_subset(set, &block)
click to toggle source
# File lib/aws_cft_tools/dependency_tree.rb, line 100 def close_subset(set, &block) find_all_available(set.to_a) { |all, acc| find_next_candidate(all, acc, &block) } end
find_all_available(candidates) { |candidates, available| ... }
click to toggle source
# File lib/aws_cft_tools/dependency_tree.rb, line 104 def find_all_available(candidates) available = [] while candidates.any? candidate = yield(candidates, available) return available unless candidate available << candidate candidates.delete(candidate) end available end
find_next_candidate(candidates, selected) { |candidate| ... }
click to toggle source
# File lib/aws_cft_tools/dependency_tree.rb, line 115 def find_next_candidate(candidates, selected) return unless block_given? candidates.detect do |candidate| (yield(candidate) - selected).empty? end end