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.



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

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.



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

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.



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

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)


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

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.



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

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)


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

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