class Puppet::Util::WatchedFile

Monitor a given file for changes on a periodic interval. Changes are detected by looking for a change in the file ctime.

Attributes

filename[R]

@!attribute [r] filename

@return [String] The fully qualified path to the file.

Public Class Methods

new(filename, timer = Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout])) click to toggle source

@param filename [String] The fully qualified path to the file. @param timer [Puppet::Util::Watcher::Timer] The polling interval for checking for file

changes. Setting the timeout to a negative value will treat the file as
always changed. Defaults to `Puppet[:filetimeout]`
   # File lib/puppet/util/watched_file.rb
14 def initialize(filename, timer = Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout]))
15   @filename = filename
16   @timer = timer
17 
18   @info = Puppet::Util::Watcher::PeriodicWatcher.new(
19     Puppet::Util::Watcher::Common.file_ctime_change_watcher(@filename),
20     timer)
21 end

Public Instance Methods

changed?() click to toggle source

@return [true, false] If the file has changed since it was last checked.

   # File lib/puppet/util/watched_file.rb
24 def changed?
25   @info.changed?
26 end
to_s() click to toggle source
   # File lib/puppet/util/watched_file.rb
34 def to_s
35   "<WatchedFile: filename = #{@filename}, timeout = #{@timer.timeout}>"
36 end
to_str() click to toggle source

Allow this to be used as the name of the file being watched in various other methods (such as Puppet::FileSystem.exist?)

   # File lib/puppet/util/watched_file.rb
30 def to_str
31   @filename
32 end