class Facts

Manage a given node’s facts. This either accepts facts and stores them, or returns facts for a given node.

Public Class Methods

from_pson(data) click to toggle source
# File lib/puppet/node/facts.rb, line 52
def self.from_pson(data)
  result = new(data['name'], data['values'])
  result.timestamp = Time.parse(data['timestamp']) if data['timestamp']
  result.expiration = Time.parse(data['expiration']) if data['expiration']
  result
end
new(name, values = {}) click to toggle source
# File lib/puppet/node/facts.rb, line 33
def initialize(name, values = {})
  @name = name
  @values = values

  add_timestamp
end

Public Instance Methods

==(other) click to toggle source
# File lib/puppet/node/facts.rb, line 47
def ==(other)
  return false unless self.name == other.name
  strip_internal == other.send(:strip_internal)
end
add_local_facts() click to toggle source
# File lib/puppet/node/facts.rb, line 28
def add_local_facts
  values["clientcert"] = Puppet.settings[:certname]
  values["clientversion"] = Puppet.version.to_s
end
add_timestamp() click to toggle source

Add internal data to the facts for storage.

# File lib/puppet/node/facts.rb, line 72
def add_timestamp
  self.timestamp = Time.now
end
stringify() click to toggle source

Convert all fact values into strings.

# File lib/puppet/node/facts.rb, line 41
def stringify
  values.each do |fact, value|
    values[fact] = value.to_s
  end
end
timestamp() click to toggle source
# File lib/puppet/node/facts.rb, line 80
def timestamp
  self.values[:_timestamp]
end
timestamp=(time) click to toggle source
# File lib/puppet/node/facts.rb, line 76
def timestamp=(time)
  self.values[:_timestamp] = time
end
to_pson(*args) click to toggle source
# File lib/puppet/node/facts.rb, line 59
def to_pson(*args)
  result = {
    'name' => name,
    'values' => strip_internal,
  }

  result['timestamp'] = timestamp if timestamp
  result['expiration'] = expiration if expiration

  result.to_pson(*args)
end

Private Instance Methods

strip_internal() click to toggle source

Strip out that internal data.

# File lib/puppet/node/facts.rb, line 87
def strip_internal
  newvals = values.dup
  newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) }
  newvals
end