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.



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

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.



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

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.



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

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)


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

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.



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

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)


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

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