]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/chef/libraries/edit_file.rb
Defer evaluation of an edited file's contents
[chef.git] / cookbooks / chef / libraries / edit_file.rb
index 1c8e263e41697f30c73352b092157e48880940f0..400e1967e0c96718f84733728d6c8d621f25963a 100644 (file)
@@ -1,9 +1,22 @@
 class Chef
 class Chef
+  class Util
+    class EditedFile
+      def initialize(file, block)
+        @file = file
+        @block = block
+      end
+
+      def to_s
+        ::File.new(@file).collect do |line|
+          line = @block.call(line)
+        end.join("")
+      end
+    end
+  end
+
   class Recipe
     def edit_file(file, &block)
   class Recipe
     def edit_file(file, &block)
-      ::File.new(file).collect do |line|
-        line = yield line
-      end.join("")
+      Chef::Util::EditedFile.new(file, block)
     end
   end
 end
     end
   end
 end