Class: AwsCftTools::DependencyTree

Inherits:
Object
  • Object
show all
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

Classes: Nodes, Variables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependencyTree

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

#filenamesObject (readonly)

Returns the value of attribute filenames.



15
16
17
# File 'lib/aws_cft_tools/dependency_tree.rb', line 15

def filenames
  @filenames
end

#nodesObject (readonly)

Returns the value of attribute nodes.



15
16
17
# File 'lib/aws_cft_tools/dependency_tree.rb', line 15

def nodes
  @nodes
end

#variablesObject (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

Parameters:

  • set (Array<T>)

Returns:

  • (Array<T>)


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_variablesObject



27
# File 'lib/aws_cft_tools/dependency_tree.rb', line 27

def_delegators :variables, :undefined_variables, :defined_variables

#dependencies_forObject



36
# File 'lib/aws_cft_tools/dependency_tree.rb', line 36

def_delegators :nodes, :dependencies_for, :dependents_for

#dependents_forObject



36
# File 'lib/aws_cft_tools/dependency_tree.rb', line 36

def_delegators :nodes, :dependencies_for, :dependents_for

#exportedObject



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.

Parameters:

  • from (#to_s)
  • to (#to_s)


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

Parameters:

  • filename (#to_s)
  • variable (String)


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

Parameters:

  • filename (#to_s)
  • variable (String)


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

#sortArray<String>

computes a topological sort and returns the filenames in that sort order

Returns:

  • (Array<String>)


43
44
45
# File 'lib/aws_cft_tools/dependency_tree.rb', line 43

def sort
  nodes.tsort & filenames
end

#undefined_variablesObject



27
# File 'lib/aws_cft_tools/dependency_tree.rb', line 27

def_delegators :variables, :undefined_variables, :defined_variables