Class: Puppet::Util::FileType
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
Instance Attribute Summary collapse
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#path ⇒ Object
Returns the value of attribute path.
-
#synced ⇒ Object
Returns the value of attribute synced.
Class Method Summary collapse
- .filetype(type) ⇒ Object
-
.newfiletype(name, &block) ⇒ Object
Create a new filetype.
Instance Method Summary collapse
-
#bucket ⇒ Object
Pick or create a filebucket to use.
-
#initialize(path) ⇒ FileType
constructor
A new instance of FileType.
Methods included from ClassGen
Methods included from Puppet::Util
activerecord_version, benchmark, chuser, classproxy, #execfail, #execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, which, withumask
Methods included from POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from SELinux
#find_fs, #get_selinux_current_context, #get_selinux_default_context, #parent_directory, #parse_selinux_context, #read_mounts, #realpath, #selinux_label_support?, #selinux_support?, #set_selinux_context, #set_selinux_default_context
Constructor Details
#initialize(path) ⇒ FileType
Returns a new instance of FileType.
78 79 80 81 |
# File 'lib/puppet/util/filetype.rb', line 78 def initialize(path) raise ArgumentError.new("Path is nil") if path.nil? @path = path end |
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/puppet/util/filetype.rb', line 13 def name @name end |
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
8 9 10 |
# File 'lib/puppet/util/filetype.rb', line 8 def loaded @loaded end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/puppet/util/filetype.rb', line 8 def path @path end |
#synced ⇒ Object
Returns the value of attribute synced.
8 9 10 |
# File 'lib/puppet/util/filetype.rb', line 8 def synced @synced end |
Class Method Details
.filetype(type) ⇒ Object
69 70 71 |
# File 'lib/puppet/util/filetype.rb', line 69 def self.filetype(type) @filetypes[type] end |
.newfiletype(name, &block) ⇒ Object
Create a new filetype.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppet/util/filetype.rb', line 18 def self.newfiletype(name, &block) @filetypes ||= {} klass = genclass( name, :block => block, :prefix => "FileType", :hash => @filetypes ) # Rename the read and write methods, so that we're sure they # maintain the stats. klass.class_eval do # Rename the read method define_method(:real_read, instance_method(:read)) define_method(:read) do begin val = real_read @loaded = Time.now if val return val.gsub(/# HEADER.*\n/,'') else return "" end rescue Puppet::Error => detail raise rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "#{self.class} could not read #{@path}: #{detail}" end end # And then the write method define_method(:real_write, instance_method(:write)) define_method(:write) do |text| begin val = real_write(text) @synced = Time.now return val rescue Puppet::Error => detail raise rescue => detail puts detail.backtrace if Puppet[:debug] raise Puppet::Error, "#{self.class} could not write #{@path}: #{detail}" end end end end |