module LegacyFacter
Functions as a hash of 'facts' about your system system, such as MAC address, IP address, architecture, etc.
@example Retrieve a fact
puts Facter['operatingsystem'].value
@example Retrieve all facts
Facter.to_hash => { "kernel"=>"Linux", "uptime_days"=>0, "ipaddress"=>"10.0.0.1" }
@api public
The resolvable mixin defines behavior for evaluating and returning fact resolutions.
Classes including this mixin should implement a name method describing the value being resolved and a resolve_value that actually executes the code to resolve the value.
The Suitable mixin provides mechanisms for confining objects to run on certain platforms and determining the run precedence of these objects.
Classes that include the Suitable mixin should define a `#confines` method that returns an Array of zero or more Facter::Util::Confine objects.
Manage which facts exist and how we access them. Largely just a wrapper around a hash of facts.
@api private
A composite loader that allows for more than one default directory loader
A module to return config related data
A restricting tag for fact resolution mechanisms. The tag must be true for the resolution mechanism to be suitable.
Load facts on demand.
This class acts as the factory and parent class for parsed facts such as scripts, text, json and yaml files.
Parsers must subclass this class and provide their own results method.
Public Class Methods
Returns a fact object by name. If you use this, you still have to call {Facter::Util::Fact#value `value`} on it to retrieve the actual value.
@param name [String] the name of the fact
@return [Facter::Util::Fact, nil] The fact object, or nil if no fact
is found.
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 79 def self.[](name) collection.fact(name) end
Adds a {Facter::Util::Resolution resolution} mechanism for a named fact. This does not distinguish between adding a new fact and adding a new way to resolve a fact.
@overload add(name, options = {}, { || … }) @param name [String] the fact name @param options [Hash] optional parameters for the fact - attributes
of {Facter::Util::Fact} and {Facter::Util::Resolution} can be supplied here
@option options [Integer] :timeout set the
{Facter::Util::Resolution#timeout timeout} for this resolution
@param block [Proc] a block defining a fact resolution
@return [Facter::Util::Fact] the fact object, which includes any previously
defined resolutions
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 158 def self.add(name, options = {}, &block) collection.add(name, options, &block) end
Clears all cached values and removes all facts from memory.
@return [void]
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 184 def self.clear LegacyFacter.flush LegacyFacter.reset end
Accessor for the collection object which holds all the facts @return [LegacyFacter::Util::Collection] the collection of facts
@api private
# 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 a new fact or extend an existing fact.
@param name [Symbol] The name of the fact to define @param options [Hash] A hash of options to set on the fact
@return [Facter::Util::Fact] The fact that was defined
@api public @see {Facter::Util::Collection#define_fact}
# 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
Iterates over fact names and values
@yieldparam [String] name the fact name @yieldparam [String] value the current value of the fact
@return [void]
@api public
# 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
(see [])
# File lib/facter/custom_facts/core/legacy_facter.rb, line 84 def self.fact(name) collection.fact(name) end
Flushes cached values for all facts. This does not cause code to be reloaded; it only clears the cached results.
@return [void]
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 94 def self.flush collection.flush end
Returns whether the JSON “feature” is available.
@api private
# File lib/facter/custom_facts/core/legacy_facter.rb, line 62 def self.json? require 'json' true rescue LoadError false end
Lists all fact names
@return [Array<String>] array of fact names
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 103 def self.list collection.list end
Loads all facts.
@return [void]
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 204 def self.loadfacts collection.load_all end
Removes all facts from memory. Use this when the fact code has changed on disk and needs to be reloaded.
@return [void]
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 195 def self.reset @collection = nil end
Gets a hash mapping fact names to their values
@return [Hash{String => Object}] the hash of fact names and values
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 123 def self.to_hash collection.load_all collection.to_hash end
Gets the value for a fact. Returns `nil` if no such fact exists.
@param name [String] the fact name @return [Object, nil] the value of the fact, or nil if no fact is
found
@api public
# File lib/facter/custom_facts/core/legacy_facter.rb, line 114 def self.value(name) collection.value(name) end