A util module for facter containing helper methods
Return a fact object by name. If you use this, you still have to call 'value' on it to retrieve the actual value.
# File lib/facter.rb, line 87 def self.[](name) collection.fact(name) end
Add 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.
# File lib/facter.rb, line 109 def self.add(name, options = {}, &block) collection.add(name, options, &block) end
Clear all facts. Mostly used for testing.
# File lib/facter.rb, line 154 def self.clear Facter.flush Facter.reset end
Clear all messages. Used only in testing. Can't add to self.clear because we don't want to warn multiple times for items that are warnonce'd
# File lib/facter.rb, line 161 def self.clear_messages @@messages.clear end
module methods
# File lib/facter.rb, line 55 def self.collection unless defined?(@collection) and @collection @collection = Facter::Util::Collection.new end @collection end
Add some debugging
# File lib/facter.rb, line 63 def self.debug(string) if string.nil? return end if self.debugging? puts GREEN + string + RESET end end
Set debugging on or off.
# File lib/facter.rb, line 166 def self.debugging(bit) if bit case bit when TrueClass; @@debug = 1 when FalseClass; @@debug = 0 when Fixnum if bit > 0 @@debug = 1 else @@debug = 0 end when String; if bit.downcase == 'off' @@debug = 0 else @@debug = 1 end else @@debug = 0 end else @@debug = 0 end end
# File lib/facter.rb, line 72 def self.debugging? @@debug != 0 end
# File lib/facter.rb, line 113 def self.each # Make sure all facts are loaded. collection.load_all collection.each do |*args| yield(*args) end end
Load all of the default facts, and then everything from disk.
# File lib/facter.rb, line 229 def self.loadfacts collection.load_all end
Allow users to call fact names directly on the Facter class, either retrieving the value or comparing it to an existing value.
# File lib/facter.rb, line 125 def method_missing(name, *args) question = false if name.to_s =~ /\?$/ question = true name = name.to_s.sub(/\?$/,'') end if fact = collection.fact(name) if question value = fact.value.downcase args.each do |arg| if arg.to_s.downcase == value return true end end # If we got this far, there was no match. return false else return fact.value end else # Else, fail like a normal missing method. raise NoMethodError, "Could not find fact '%s'" % name end end
Remove them all.
# File lib/facter.rb, line 224 def self.reset @collection = nil end
Register a directory to search through.
# File lib/facter.rb, line 236 def self.search(*dirs) @search_path += dirs end
Return our registered search directories.
# File lib/facter.rb, line 241 def self.search_path @search_path.dup end
show the timing information
# File lib/facter.rb, line 77 def self.show_time(string) puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing? end
Set timing on or off.
# File lib/facter.rb, line 192 def self.timing(bit) if bit case bit when TrueClass; @@timing = 1 when Fixnum if bit > 0 @@timing = 1 else @@timing = 0 end end else @@timing = 0 end end
# File lib/facter/version.rb, line 6 def self.version @facter_version || FACTERVERSION end
# File lib/facter/version.rb, line 10 def self.version=(version) @facter_version = version end
Generated with the Darkfish Rdoc Generator 2.