Module: LegacyFacter

Extended by:
Core::Logging
Includes:
Comparable, Enumerable
Defined in:
lib/facter/custom_facts/util/config.rb,
lib/facter/custom_facts/util/loader.rb,
lib/facter/custom_facts/util/parser.rb,
lib/facter/custom_facts/util/values.rb,
lib/facter/custom_facts/core/logging.rb,
lib/facter/custom_facts/util/confine.rb,
lib/facter/custom_facts/core/suitable.rb,
lib/facter/custom_facts/util/unix_root.rb,
lib/facter/custom_facts/core/resolvable.rb,
lib/facter/custom_facts/util/collection.rb,
lib/facter/custom_facts/util/windows_root.rb,
lib/facter/custom_facts/core/legacy_facter.rb,
lib/facter/custom_facts/util/normalization.rb,
lib/facter/custom_facts/core/directed_graph.rb,
lib/facter/custom_facts/util/nothing_loader.rb,
lib/facter/custom_facts/util/composite_loader.rb,
lib/facter/custom_facts/util/directory_loader.rb

Overview

A composite loader that allows for more than one default directory loader

Defined Under Namespace

Modules: Core, Util

Constant Summary

Constants included from Core::Logging

Core::Logging::GREEN, Core::Logging::RED, Core::Logging::RESET

Class Method Summary collapse

Methods included from Core::Logging

clear_messages, debug, debugging, debugging?, debugonce, format_exception, log_exception, on_message, show_time, timing, timing?, trace, trace?, warn, warnonce

Class Method Details

.[](name) ⇒ Facter::Util::Fact?

Returns a fact object by name. If you use this, you still have to call value on it to retrieve the actual value.



79
80
81
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 79

def self.[](name)
  collection.fact(name)
end

.add(name, options = {}, { || ... }) ⇒ Facter::Util::Fact

Adds a resolution mechanism for a named fact. This does not distinguish between adding a new fact and adding a new way to resolve a fact.

Options Hash (options):

  • :timeout (Integer)

    set the timeout for this resolution



158
159
160
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 158

def self.add(name, options = {}, &block)
  collection.add(name, options, &block)
end

.clearvoid

This method returns an undefined value.

Clears all cached values and removes all facts from memory.



184
185
186
187
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 184

def self.clear
  LegacyFacter.flush
  LegacyFacter.reset
end

.collectionLegacyFacter::Util::Collection

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.

Accessor for the collection object which holds all the facts



49
50
51
52
53
54
55
56
57
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 49

def self.collection
  unless defined?(@collection) && @collection
    @collection = LegacyFacter::Util::Collection.new(
      LegacyFacter::Util::Loader.new,
      LegacyFacter::Util::Config.ext_fact_loader
    )
  end
  @collection
end

.define_fact(name, options = {}, &block) ⇒ Facter::Util::Fact

Define a new fact or extend an existing fact.

See Also:

  • {Facter{Facter::Util{Facter::Util::Collection{Facter::Util::Collection#define_fact}


137
138
139
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 137

def self.define_fact(name, options = {}, &block)
  collection.define_fact(name, options, &block)
end

.each {|name, value| ... } ⇒ void

This method returns an undefined value.

Iterates over fact names and values

Yield Parameters:

  • name (String)

    the fact name

  • value (String)

    the current value of the fact



170
171
172
173
174
175
176
177
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 170

def self.each
  # Make sure all facts are loaded.
  collection.load_all

  collection.each do |*args|
    yield(*args)
  end
end

.fact(name) ⇒ Facter::Util::Fact?

Returns a fact object by name. If you use this, you still have to call value on it to retrieve the actual value.



84
85
86
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 84

def self.fact(name)
  collection.fact(name)
end

.flushvoid

This method returns an undefined value.

Flushes cached values for all facts. This does not cause code to be reloaded; it only clears the cached results.



94
95
96
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 94

def self.flush
  collection.flush
end

.json?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 whether the JSON “feature” is available.



62
63
64
65
66
67
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 62

def self.json?
  require 'json'
  true
rescue LoadError
  false
end

.listArray<String>

Lists all fact names



103
104
105
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 103

def self.list
  collection.list
end

.loadfactsvoid

This method returns an undefined value.

Loads all facts.



204
205
206
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 204

def self.loadfacts
  collection.load_all
end

.resetvoid

This method returns an undefined value.

Removes all facts from memory. Use this when the fact code has changed on disk and needs to be reloaded.



195
196
197
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 195

def self.reset
  @collection = nil
end

.to_hashHash{String => Object}

Gets a hash mapping fact names to their values



123
124
125
126
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 123

def self.to_hash
  collection.load_all
  collection.to_hash
end

.value(name) ⇒ Object?

Gets the value for a fact. Returns nil if no such fact exists.



114
115
116
# File 'lib/facter/custom_facts/core/legacy_facter.rb', line 114

def self.value(name)
  collection.value(name)
end