We want to make sure we don't build the contents until the resource
is asctually being run, as it may rely on template files installed by
a previous resource.
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)
- ::File.new(file).collect do |line|
- line = yield line
- end.join("")
+ Chef::Util::EditedFile.new(file, block)
end
end
end