]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/chef/libraries/edit_file.rb
Make deferring of edit_file work properly
[chef.git] / cookbooks / chef / libraries / edit_file.rb
index 1c8e263e41697f30c73352b092157e48880940f0..8a04a8090f3e45ce03a13e71bbba768d9b945376 100644 (file)
@@ -1,9 +1,26 @@
 class Chef
+  class Util
+    class EditedFile
+      def initialize(file, block)
+        @file = file
+        @block = block
+      end
+
+      def kind_of?(klass)
+        klass == String || super
+      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)
-      ::File.new(file).collect do |line|
-        line = yield line
-      end.join("")
+      Chef::Util::EditedFile.new(file, block)
     end
   end
 end