Allow up to 10 levels of nesting for variable substitution in config.rb
authorWard Vandewege <ward@clinicalfuture.com>
Mon, 11 Nov 2013 21:38:03 +0000 (16:38 -0500)
committerWard Vandewege <ward@clinicalfuture.com>
Mon, 11 Nov 2013 21:38:03 +0000 (16:38 -0500)
docker/config.rb

index 49004dad825b4f8c915e4374de4e704b18e98349..c96819e506776b39f81dadc5b67ab2d85ceaa2f4 100755 (executable)
@@ -29,14 +29,24 @@ end
 # ============================================================
 # For each *.in file in the docker directories, substitute any
 # @@variables@@ found in the file with the appropriate config
-# variable.
+# variable. Support up to 10 levels of nesting.
 
 Dir.glob('*/*.in') do |template_file|
   output_path = template_file.sub(/\.in$/, '')
   output = File.open(output_path, "w")
   File.open(template_file) do |input|
     input.each_line do |line|
-      output.write(line.gsub(/@@(.*?)@@/) { |var| config[$1] || var })
+
+      @count = 0
+      while @count < 10
+        @out = line.gsub!(/@@(.*?)@@/) do |var|
+          config[Regexp.last_match[1]] || var.gsub!(/@@/, '@_NOT_FOUND_@')
+        end
+        break if @out.nil?
+        @count += 1
+      end
+
+      output.write(line)
     end
   end
   output.close