class Puppet::Util::Watcher::PeriodicWatcher

Monitor a given watcher for changes on a periodic interval.

Public Class Methods

new(watcher, timer) click to toggle source

@param watcher [Puppet::Util::Watcher::ChangeWatcher] a watcher for the value to watch @param timer [Puppet::Util::Watcher::Timer] A timer to determine when to

recheck the watcher. If the timeout of the timer is negative, then the
watched value is always considered to be changed
   # File lib/puppet/util/watcher/periodic_watcher.rb
 8 def initialize(watcher, timer)
 9   @watcher = watcher
10   @timer = timer
11 
12   @timer.start
13 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/watcher/periodic_watcher.rb
16 def changed?
17   return true if always_consider_changed?
18 
19   @watcher = examine_watched_info(@watcher)
20   @watcher.changed?
21 end

Private Instance Methods

always_consider_changed?() click to toggle source
   # File lib/puppet/util/watcher/periodic_watcher.rb
25 def always_consider_changed?
26   @timer.timeout < 0
27 end
examine_watched_info(known) click to toggle source
   # File lib/puppet/util/watcher/periodic_watcher.rb
29 def examine_watched_info(known)
30   if @timer.expired?
31     @timer.start
32     known.next_reading
33   else
34     known
35   end
36 end