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


14
15
16
17
18
19
20
21
# File 'lib/puppet/util/watched_file.rb', line 14

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


8
9
10
# File 'lib/puppet/util/watched_file.rb', line 8

def filename
  @filename
end

Instance Method Details

#changed?true, false


24
25
26
# File 'lib/puppet/util/watched_file.rb', line 24

def changed?
  @info.changed?
end

#to_sObject


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

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?)


30
31
32
# File 'lib/puppet/util/watched_file.rb', line 30

def to_str
  @filename
end