]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/libraries/edit_file.rb
Defer evaluation of an edited file's contents
[chef.git] / cookbooks / chef / libraries / edit_file.rb
1 class Chef
2   class Util
3     class EditedFile
4       def initialize(file, block)
5         @file = file
6         @block = block
7       end
8
9       def to_s
10         ::File.new(@file).collect do |line|
11           line = @block.call(line)
12         end.join("")
13       end
14     end
15   end
16
17   class Recipe
18     def edit_file(file, &block)
19       Chef::Util::EditedFile.new(file, block)
20     end
21   end
22 end