module RFacter::DSL::Facter
DSL
for top-level Facter
methods
@todo Implement `reset` @todo Implement `search`
Public Class Methods
Returns a fact object by name.
If you use this, you still have to call {RFacter::Util::Fact#value `value`} on it to retrieve the actual value.
@param name [String, Symbol] the name of the fact
@return [RFacter::Util::Fact, nil] The fact object, or nil if no fact
is found.
# File lib/rfacter/dsl.rb, line 50 def self.[](name) COLLECTION.value.fact(name) end
Adds a {RFacter::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 {RFacter::Util::Fact} and {Facter::Util::Resolution} can be supplied here
@option options [Integer] :timeout set the
{RFacter::Core::Resolvable#timeout timeout} for this resolution
@param block [Proc] a block defining a fact resolution
@return [RFacter::Util::Fact] the fact object, which includes any previously
defined resolutions
# File lib/rfacter/dsl.rb, line 69 def self.add(name, options = {}, &block) COLLECTION.value.add(name, options, &block) end
Clears all cached values and removes all facts from memory.
@return [void]
# File lib/rfacter/dsl.rb, line 76 def self.clear self.flush self.reset end
Prints a debug message if debugging is turned on
@param msg [String] the debug message
@return [void]
# File lib/rfacter/dsl.rb, line 86 def self.debug(msg) ::RFacter::Config.config.logger.debug(msg) end
Prints a debug message only once.
@note Uniqueness is based on the string, not the specific location
of the method call.
@param msg [String] the debug message @return [void]
# File lib/rfacter/dsl.rb, line 97 def self.debugonce(msg) ::RFacter::Config.config.logger.debugonce(msg) 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 [RFacter::Util::Fact] The fact that was defined
@see RFacter::Util::Collection#define_fact
# File lib/rfacter/dsl.rb, line 109 def self.define_fact(name, options = {}, &block) COLLECTION.value.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]
# File lib/rfacter/dsl.rb, line 119 def self.each COLLECTION.value.each do |*args| yield(*args) end end
(see [])
# File lib/rfacter/dsl.rb, line 126 def self.fact(name) COLLECTION.value.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]
# File lib/rfacter/dsl.rb, line 134 def self.flush COLLECTION.value.flush end
Lists all fact names
@return [Array<String>] array of fact names
# File lib/rfacter/dsl.rb, line 141 def self.list COLLECTION.value.list end
Loads all facts.
@return [void]
# File lib/rfacter/dsl.rb, line 148 def self.loadfacts COLLECTION.value.load_all end
# File lib/rfacter/dsl.rb, line 152 def self.log_exception(exception, message = nil) ::RFacter::Config.config.logger.log_exception(exception, messge) end
Removes all facts from memory. Use this when the fact code has changed on disk and needs to be reloaded.
@note This is currently a no-op for RFacter
pending changes to how
collections are handled.
@return [void]
# File lib/rfacter/dsl.rb, line 163 def self.reset end
Register directories to be searched for facts. The registered directories must be absolute paths or they will be ignored.
@param dirs [String] directories to search
@note This is currently a no-op for RFacter
pending changes to how
collections are handled.
@return [void]
# File lib/rfacter/dsl.rb, line 175 def self.search(*dirs) end
Returns the registered search directories.
@return [Array<String>] An array of the directories searched
# File lib/rfacter/dsl.rb, line 181 def self.search_path COLLECTION.value.search_path end
Gets a hash mapping fact names to their values.
@return [Hash{String => Object}] the hash of fact names and values
# File lib/rfacter/dsl.rb, line 188 def self.to_hash COLLECTION.value.to_hash end
Gets the value for a fact.
@param name [String, Symbol] the fact name
@return [Object, nil] the value of the fact, or nil if no fact is
found
# File lib/rfacter/dsl.rb, line 198 def self.value(name) COLLECTION.value.value(name) end
Returns the current RFacter
version
@return [String]
# File lib/rfacter/dsl.rb, line 205 def self.version RFacter::VERSION end
Prints a warning message. The message is only printed if debugging is enabled.
@param msg [String] the warning message to be printed
@return [void]
# File lib/rfacter/dsl.rb, line 215 def self.warn(msg) ::RFacter::Config.config.logger.warn(msg) end
Prints a warning message only once per process. Each unique string is printed once.
@note Unlike {warn} the message will be printed even if debugging is
not turned on. This behavior is likely to change and should not be relied on.
@param msg [String] the warning message to be printed
@return [void]
# File lib/rfacter/dsl.rb, line 230 def self.warnonce(msg) ::RFacter::Config.config.logger.warnonce(msg) end