# File lib/puppet/util/filetype.rb, line 18
18:   def self.newfiletype(name, &block)
19:     @filetypes ||= {}
20: 
21: 
22:           klass = genclass(
23:         name,
24:       :block => block,
25:       :prefix => "FileType",
26:         
27:       :hash => @filetypes
28:     )
29: 
30:     # Rename the read and write methods, so that we're sure they
31:     # maintain the stats.
32:     klass.class_eval do
33:       # Rename the read method
34:       define_method(:real_read, instance_method(:read))
35:       define_method(:read) do
36:         begin
37:           val = real_read
38:           @loaded = Time.now
39:           if val
40:             return val.gsub(/# HEADER.*\n/,'')
41:           else
42:             return ""
43:           end
44:         rescue Puppet::Error => detail
45:           raise
46:         rescue => detail
47:           puts detail.backtrace if Puppet[:trace]
48:           raise Puppet::Error, "#{self.class} could not read #{@path}: #{detail}"
49:         end
50:       end
51: 
52:       # And then the write method
53:       define_method(:real_write, instance_method(:write))
54:       define_method(:write) do |text|
55:         begin
56:           val = real_write(text)
57:           @synced = Time.now
58:           return val
59:         rescue Puppet::Error => detail
60:           raise
61:         rescue => detail
62:           puts detail.backtrace if Puppet[:debug]
63:           raise Puppet::Error, "#{self.class} could not write #{@path}: #{detail}"
64:         end
65:       end
66:     end
67:   end