Class: StackMate::Stacker
- Inherits:
-
Object
- Object
- StackMate::Stacker
show all
- Includes:
- Logging, TSort
- Defined in:
- lib/stackmate/stack.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
configure_logger_for, #logger, logger_for
Constructor Details
#initialize(stackstr, stackname, params) ⇒ Stacker
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/stackmate/stack.rb', line 14
def initialize(stackstr, stackname, params)
@stackname = stackname
@resolved = params
@templ = JSON.parse(stackstr)
@templ['StackName'] = @stackname
@param_names = @templ['Parameters']
@deps = {}
@pdeps = {}
validate_param_values
resolve_dependencies()
@templ['ResolvedNames'] = @resolved
end
|
Instance Attribute Details
#templ ⇒ Object
Returns the value of attribute templ.
12
13
14
|
# File 'lib/stackmate/stack.rb', line 12
def templ
@templ
end
|
Instance Method Details
#find_refs(parent, jsn, deps, pdeps) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/stackmate/stack.rb', line 58
def find_refs (parent, jsn, deps, pdeps)
case jsn
when Array
jsn.each {|x| find_refs(parent, x, deps, pdeps)}
when Hash
jsn.keys.each do |k|
if k == "Ref"
if !@param_names.keys.index(jsn[k]) && jsn[k] != 'AWS::Region' && jsn[k] != 'AWS::StackId' && jsn[k] != 'AWS::StackName'
deps << jsn[k]
else if @param_names.keys.index(jsn[k])
pdeps << jsn[k]
end
end
else
find_refs(parent, jsn[k], deps, pdeps)
end
end
end
return deps
end
|
#resolve_dependencies ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/stackmate/stack.rb', line 33
def resolve_dependencies
@templ['Resources'].each { |key,val|
deps = Set.new
pdeps = Set.new
find_refs(key, val, deps, pdeps)
deps << val['DependsOn'] if val['DependsOn']
@deps[key] = deps.to_a
@pdeps[key] = pdeps.to_a
}
@pdeps.keys.each do |k|
unres = @pdeps[k] - @resolved.keys
if ! unres.empty?
unres.each do |u|
deflt = @param_names[u]['Default']
@resolved[u] = deflt if deflt
end
unres = @pdeps[k] - @resolved.keys
throw :unresolved, (@pdeps[k] - @resolved.keys) if !unres.empty?
end
end
end
|
#tsort_each_child(name, &block) ⇒ Object
87
88
89
|
# File 'lib/stackmate/stack.rb', line 87
def tsort_each_child(name, &block)
@deps[name].each(&block) if @deps.has_key?(name)
end
|
#tsort_each_node(&block) ⇒ Object
83
84
85
|
# File 'lib/stackmate/stack.rb', line 83
def tsort_each_node(&block)
@deps.each_key(&block)
end
|
#validate_param_values ⇒ Object
28
29
30
31
|
# File 'lib/stackmate/stack.rb', line 28
def validate_param_values
end
|