Class: Lono::Template::PostProcessor
Instance Method Summary
collapse
#initialize, #reinitialize
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#registry_items ⇒ Object
54
55
56
|
# File 'lib/lono/template/post_processor.rb', line 54
def registry_items
Lono::AppFile::Registry.items
end
|
#replacements ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/lono/template/post_processor.rb', line 14
def replacements
map = {}
registry_items.each do |item|
if item.type == "lambda_layer"
placeholder = "file://app/files/lambda_layer/#{item.name}"
elsif item.directory? || item.file?
placeholder = "file://app/files/file/#{item.name}"
else
puts "WARN: PostProcessor replacements Cannot find file: #{item.output_path}"
next
end
map[placeholder] = item.s3_path
end
Lono::Configset::S3File::Registry.items.each do |item|
placeholder = "file://configset/#{item.configset}/#{item.name}"
map[placeholder] = item.replacement_value
end
map
end
|
#run ⇒ Object
3
4
5
6
7
8
|
# File 'lib/lono/template/post_processor.rb', line 3
def run
replacements.each do |placeholder, replacement|
update_template!(template)
end
write_template!
end
|
#template ⇒ Object
58
59
60
|
# File 'lib/lono/template/post_processor.rb', line 58
def template
YAML.load_file(template_path)
end
|
#template_path ⇒ Object
63
64
65
|
# File 'lib/lono/template/post_processor.rb', line 63
def template_path
"#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
end
|
#update_template!(hash) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/lono/template/post_processor.rb', line 38
def update_template!(hash)
hash.each do |k, v|
if v.is_a?(String)
if v =~ %r{^file://}
v.replace(replacements[v])
end
elsif v.is_a?(Hash)
update_template!(v)
elsif v.is_a?(Array)
v.each { |x| update_template!(x) if x.is_a?(Hash) }
end
end
hash
end
|
#write_template! ⇒ Object
10
11
12
|
# File 'lib/lono/template/post_processor.rb', line 10
def write_template!
IO.write(template_path, YAML.dump(template))
end
|