Class: AwsCftTools::DependencyTree
- Inherits:
-
Object
- Object
- AwsCftTools::DependencyTree
- Extended by:
- Forwardable
- Defined in:
- lib/aws_cft_tools/dependency_tree.rb,
lib/aws_cft_tools/dependency_tree/nodes.rb,
lib/aws_cft_tools/dependency_tree/variables.rb
Overview
Dependency Tree
Manage dependencies between CloudFormation templates based on exported and imported variables.
Defined Under Namespace
Instance Attribute Summary collapse
-
#filenames ⇒ Object
readonly
Returns the value of attribute filenames.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#closed_subset(set) ⇒ Array<T>
finds a subset of the given set that has no dependencies outside the set.
- #defined_variables ⇒ Object
- #dependencies_for ⇒ Object
- #dependents_for ⇒ Object
- #exported ⇒ Object
-
#initialize ⇒ DependencyTree
constructor
A new instance of DependencyTree.
-
#linked(from, to) ⇒ Object
links two nodes in a directed fashion.
-
#provided(filename, variable) ⇒ Object
notes that the given filename defines the given variable name.
-
#required(filename, variable) ⇒ Object
notes that the given filename requires the given variable name to be defined before deployment.
-
#sort ⇒ Array<String>
computes a topological sort and returns the filenames in that sort order.
- #undefined_variables ⇒ Object
Constructor Details
#initialize ⇒ DependencyTree
Returns a new instance of DependencyTree.
17 18 19 20 21 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 17 def initialize @nodes = Nodes.new @variables = Variables.new @filenames = [] end |
Instance Attribute Details
#filenames ⇒ Object (readonly)
Returns the value of attribute filenames.
15 16 17 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 15 def filenames @filenames end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
15 16 17 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 15 def nodes @nodes end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
15 16 17 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 15 def variables @variables end |
Instance Method Details
#closed_subset(set) ⇒ Array<T>
finds a subset of the given set that has no dependencies outside the set
93 94 95 96 |
# 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 |
#defined_variables ⇒ Object
27 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 27 def_delegators :variables, :undefined_variables, :defined_variables |
#dependencies_for ⇒ Object
36 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 36 def_delegators :nodes, :dependencies_for, :dependents_for |
#dependents_for ⇒ Object
36 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 36 def_delegators :nodes, :dependencies_for, :dependents_for |
#exported ⇒ Object
30 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 30 def_delegator :variables, :defined, :exported |
#linked(from, to) ⇒ Object
links two nodes in a directed fashion
The template named by from provides resources required by the template named by to.
81 82 83 84 85 |
# 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) ⇒ Object
notes that the given filename defines the given variable name
53 54 55 56 57 58 |
# 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) ⇒ Object
notes that the given filename requires the given variable name to be defined before deployment
66 67 68 69 70 71 |
# 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 ⇒ Array<String>
computes a topological sort and returns the filenames in that sort order
43 44 45 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 43 def sort nodes.tsort & filenames end |
#undefined_variables ⇒ Object
27 |
# File 'lib/aws_cft_tools/dependency_tree.rb', line 27 def_delegators :variables, :undefined_variables, :defined_variables |