Module: LegacyFacter

Extended by:
Core::Logging
Includes:
Comparable, Enumerable
Defined in:
lib/custom_facts/util/config.rb,
lib/custom_facts/version.rb,
lib/custom_facts/util/loader.rb,
lib/custom_facts/util/parser.rb,
lib/custom_facts/util/values.rb,
lib/custom_facts/core/logging.rb,
lib/custom_facts/util/confine.rb,
lib/custom_facts/core/suitable.rb,
lib/custom_facts/util/unix_root.rb,
lib/custom_facts/core/resolvable.rb,
lib/custom_facts/util/collection.rb,
lib/custom_facts/util/windows_root.rb,
lib/custom_facts/core/legacy_facter.rb,
lib/custom_facts/util/normalization.rb,
lib/custom_facts/core/directed_graph.rb,
lib/custom_facts/util/nothing_loader.rb,
lib/custom_facts/util/composite_loader.rb,
lib/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 collapse

FACTERVERSION =
'2.5.5'

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.

Parameters:

  • name (String)

    the name of the fact

Returns:



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

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.

Parameters:

  • name (String)

    the fact name

  • options (Hash) (defaults to: {})

    optional parameters for the fact - attributes of Facter::Util::Fact and Facter::Util::Resolution can be supplied here

  • block (Proc)

    a block defining a fact resolution

Options Hash (options):

  • :timeout (Integer)

    set the timeout for this resolution

Returns:

  • (Facter::Util::Fact)

    the fact object, which includes any previously defined resolutions



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

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.



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

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

Returns:



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

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.

Parameters:

  • name (Symbol)

    The name of the fact to define

  • options (Hash) (defaults to: {})

    A hash of options to set on the fact

Returns:

See Also:

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


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

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



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

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.

Parameters:

  • name (String)

    the name of the fact

Returns:



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

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.



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

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.

Returns:

  • (Boolean)


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

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

.listArray<String>

Lists all fact names

Returns:

  • (Array<String>)

    array of fact names



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

def self.list
  collection.list
end

.loadfactsvoid

This method returns an undefined value.

Loads all facts.



206
207
208
# File 'lib/custom_facts/core/legacy_facter.rb', line 206

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.



196
197
198
199
# File 'lib/custom_facts/core/legacy_facter.rb', line 196

def self.reset
  @collection = nil
  reset_search_path!
end

.reset_search_path!void

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.

This method returns an undefined value.

Reset the Facter search directories.



235
236
237
# File 'lib/custom_facts/core/legacy_facter.rb', line 235

def self.reset_search_path!
  @search_path = []
end

.search(*dirs) ⇒ void

This method returns an undefined value.

Register directories to be searched for facts. The registered directories must be absolute paths or they will be ignored.

Parameters:

  • dirs (String)

    directories to search



218
219
220
# File 'lib/custom_facts/core/legacy_facter.rb', line 218

def self.search(*dirs)
  @search_path += dirs
end

.search_external(dirs) ⇒ void

This method returns an undefined value.

Registers directories to be searched for external facts.

Parameters:

  • dirs (Array<String>)

    directories to search



248
249
250
# File 'lib/custom_facts/core/legacy_facter.rb', line 248

def self.search_external(dirs)
  LegacyFacter::Util::Config.external_facts_dirs += dirs
end

.search_external_pathArray<String>

Returns the registered search directories.

Returns:

  • (Array<String>)

    An array of the directories searched



257
258
259
# File 'lib/custom_facts/core/legacy_facter.rb', line 257

def self.search_external_path
  LegacyFacter::Util::Config.external_facts_dirs.dup
end

.search_pathArray<String>

Returns the registered search directories.

Returns:

  • (Array<String>)

    An array of the directories searched



227
228
229
# File 'lib/custom_facts/core/legacy_facter.rb', line 227

def self.search_path
  @search_path.dup
end

.to_hashHash{String => Object}

Gets a hash mapping fact names to their values

Returns:

  • (Hash{String => Object})

    the hash of fact names and values



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

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.

Parameters:

  • name (String)

    the fact name

Returns:

  • (Object, nil)

    the value of the fact, or nil if no fact is found



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

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

.versionString

Returns the running version of Facter.

Returns:

  • (String)

    containing the custom_facts version, e.g. “1.6.14”



55
56
57
58
59
60
61
62
63
# File 'lib/custom_facts/version.rb', line 55

def self.version
  version_file = File.join(File.dirname(__FILE__), 'VERSION')
  return @version if @version

  if (version = read_version_file(version_file))
    @version = version
  end
  @version ||= FACTERVERSION
end

.version=(version) ⇒ void

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.

This method returns an undefined value.

Sets the Facter version



70
71
72
# File 'lib/custom_facts/version.rb', line 70

def self.version=(version)
  @version = version
end