Class: Puppet::Util::Watcher::ChangeWatcher Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Watches for changes over time. It only re-examines the values when it is requested to update readings.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous, current, value_reader) ⇒ ChangeWatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChangeWatcher.



8
9
10
11
12
# File 'lib/puppet/util/watcher/change_watcher.rb', line 8

def initialize(previous, current, value_reader)
  @previous = previous
  @current = current
  @value_reader = value_reader
end

Class Method Details

.watch(reader) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



4
5
6
# File 'lib/puppet/util/watcher/change_watcher.rb', line 4

def self.watch(reader)
  Puppet::Util::Watcher::ChangeWatcher.new(nil, nil, reader).next_reading
end

Instance Method Details

#change_current_reading_to(new_value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/puppet/util/watcher/change_watcher.rb', line 26

def change_current_reading_to(new_value)
  Puppet::Util::Watcher::ChangeWatcher.new(@current, new_value, @value_reader)
end

#changed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

def changed?
  if uncertain?
    false
  else
    @previous != @current
  end
end

#next_readingObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def next_reading
  change_current_reading_to(@value_reader.call)
end

#uncertain?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


22
23
24
# File 'lib/puppet/util/watcher/change_watcher.rb', line 22

def uncertain?
  @previous.nil? || @current.nil?
end