Class: Puppet::Util::WatchedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/watched_file.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, timer = Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout])) ⇒ WatchedFile

Returns a new instance of WatchedFile.

Parameters:

  • filename (String)

    The fully qualified path to the file.

  • timer (Puppet::Util::Watcher::Timer) (defaults to: Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout]))

    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`



16
17
18
19
20
21
22
23
24
# File 'lib/puppet/util/watched_file.rb', line 16

def initialize(filename, timer = Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout]))
  @filename = filename
  @timer = timer

  @info = Puppet::Util::Watcher::PeriodicWatcher.new(
    Puppet::Util::Watcher::Common.file_ctime_change_watcher(@filename),
    timer
  )
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/puppet/util/watched_file.rb', line 10

def filename
  @filename
end

Instance Method Details

#changed?true, false

Returns If the file has changed since it was last checked.

Returns:

  • (true, false)

    If the file has changed since it was last checked.



27
28
29
# File 'lib/puppet/util/watched_file.rb', line 27

def changed?
  @info.changed?
end

#to_sObject



37
38
39
# File 'lib/puppet/util/watched_file.rb', line 37

def to_s
  "<WatchedFile: filename = #{@filename}, timeout = #{@timer.timeout}>"
end

#to_strObject

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



33
34
35
# File 'lib/puppet/util/watched_file.rb', line 33

def to_str
  @filename
end