From: Tom Hughes Date: Sat, 23 Nov 2013 11:48:42 +0000 (+0000) Subject: Defer evaluation of an edited file's contents X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/7f6415938eb888893b49cc968a5c01082743b7d7?ds=inline Defer evaluation of an edited file's contents 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. --- diff --git a/cookbooks/chef/libraries/edit_file.rb b/cookbooks/chef/libraries/edit_file.rb index 1c8e263e4..400e1967e 100644 --- a/cookbooks/chef/libraries/edit_file.rb +++ b/cookbooks/chef/libraries/edit_file.rb @@ -1,9 +1,22 @@ 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