class Lono::Template::PostProcessor
Public Instance Methods
registry_items()
click to toggle source
Useful for specs
# File lib/lono/template/post_processor.rb, line 54 def registry_items Lono::AppFile::Registry.items end
replacements()
click to toggle source
# 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] = "https://s3.amazonaws.com/#{Lono::S3::Bucket.name}/#{item.s3_path}" map[placeholder] = item.replacement_value end map end
run()
click to toggle source
# File lib/lono/template/post_processor.rb, line 3 def run replacements.each do |placeholder, replacement| update_template!(template) end write_template! end
template()
click to toggle source
# File lib/lono/template/post_processor.rb, line 58 def template YAML.load_file(template_path) end
template_path()
click to toggle source
# File lib/lono/template/post_processor.rb, line 63 def template_path "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml" end
update_template!(hash)
click to toggle source
# 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]) # replace the placeholder end elsif v.is_a?(Hash) update_template!(v) # recurse elsif v.is_a?(Array) v.each { |x| update_template!(x) if x.is_a?(Hash) } end end hash end
write_template!()
click to toggle source
# File lib/lono/template/post_processor.rb, line 10 def write_template! IO.write(template_path, YAML.dump(template)) # unless ENV['LONO_TEST'] # additional safeguard for testing end