Included Modules

Facter

A util module for facter containing helper methods


Facter - Host Fact Detection and Reporting

Copyright 2011 Puppet Labs Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constants

FACTERVERSION
GREEN
RESET

Public Class Methods

[](name) click to toggle source

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 91
91:   def self.[](name)
92:     collection.fact(name)
93:   end
add(name, options = {}, &block) click to toggle source

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 113
113:   def self.add(name, options = {}, &block)
114:     collection.add(name, options, &block)
115:   end
clear() click to toggle source

Clear all facts. Mostly used for testing.

     # File lib/facter.rb, line 158
158:   def self.clear
159:     Facter.flush
160:     Facter.reset
161:   end
clear_messages() click to toggle source

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 165
165:   def self.clear_messages
166:     @@messages.clear
167:   end
collection() click to toggle source

module methods

    # File lib/facter.rb, line 54
54:   def self.collection
55:     unless defined?(@collection) and @collection
56:       @collection = Facter::Util::Collection.new
57:     end
58:     @collection
59:   end
debug(string) click to toggle source

Add some debugging

    # File lib/facter.rb, line 67
67:   def self.debug(string)
68:     if string.nil?
69:       return
70:     end
71:     if self.debugging?
72:       puts GREEN + string + RESET
73:     end
74:   end
debugging(bit) click to toggle source

Set debugging on or off.

     # File lib/facter.rb, line 170
170:   def self.debugging(bit)
171:     if bit
172:       case bit
173:       when TrueClass; @@debug = 1
174:       when FalseClass; @@debug = 0
175:       when Fixnum
176:         if bit > 0
177:           @@debug = 1
178:         else
179:           @@debug = 0
180:         end
181:       when String;
182:         if bit.downcase == 'off'
183:           @@debug = 0
184:         else
185:           @@debug = 1
186:         end
187:       else
188:         @@debug = 0
189:       end
190:     else
191:       @@debug = 0
192:     end
193:   end
debugging?() click to toggle source
    # File lib/facter.rb, line 76
76:   def self.debugging?
77:     @@debug != 0
78:   end
each() click to toggle source
     # File lib/facter.rb, line 117
117:   def self.each
118:     # Make sure all facts are loaded.
119:     collection.load_all
120: 
121:     collection.each do |*args|
122:       yield(*args)
123:     end
124:   end
loadfacts() click to toggle source

Load all of the default facts, and then everything from disk.

     # File lib/facter.rb, line 233
233:   def self.loadfacts
234:     collection.load_all
235:   end
method_missing(name, *args) click to toggle source

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 129
129:     def method_missing(name, *args)
130:       question = false
131:       if name.to_s =~ /\?$/
132:         question = true
133:         name = name.to_s.sub(/\?$/,'')
134:       end
135: 
136:       if fact = collection.fact(name)
137:         if question
138:           value = fact.value.downcase
139:           args.each do |arg|
140:             if arg.to_s.downcase == value
141:               return true
142:             end
143:           end
144: 
145:           # If we got this far, there was no match.
146:           return false
147:         else
148:           return fact.value
149:         end
150:       else
151:         # Else, fail like a normal missing method.
152:         raise NoMethodError, "Could not find fact '%s'" % name
153:       end
154:     end
reset() click to toggle source

Remove them all.

     # File lib/facter.rb, line 228
228:   def self.reset
229:     @collection = nil
230:   end
search(*dirs) click to toggle source

Register a directory to search through.

     # File lib/facter.rb, line 240
240:   def self.search(*dirs)
241:     @search_path += dirs
242:   end
search_path() click to toggle source

Return our registered search directories.

     # File lib/facter.rb, line 245
245:   def self.search_path
246:     @search_path.dup
247:   end
show_time(string) click to toggle source

show the timing information

    # File lib/facter.rb, line 81
81:   def self.show_time(string)
82:     puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
83:   end
timing(bit) click to toggle source

Set timing on or off.

     # File lib/facter.rb, line 196
196:   def self.timing(bit)
197:     if bit
198:       case bit
199:       when TrueClass; @@timing = 1
200:       when Fixnum
201:         if bit > 0
202:           @@timing = 1
203:         else
204:           @@timing = 0
205:         end
206:       end
207:     else
208:       @@timing = 0
209:     end
210:   end
timing?() click to toggle source
    # File lib/facter.rb, line 85
85:   def self.timing?
86:     @@timing != 0
87:   end
version() click to toggle source

Return the version of the library.

    # File lib/facter.rb, line 62
62:   def self.version
63:     return FACTERVERSION
64:   end
warn(msg) click to toggle source
     # File lib/facter.rb, line 212
212:   def self.warn(msg)
213:     if Facter.debugging? and msg and not msg.empty?
214:       msg = [msg] unless msg.respond_to? :each
215:       msg.each { |line| Kernel.warn line }
216:     end
217:   end
warnonce(msg) click to toggle source

Warn once.

     # File lib/facter.rb, line 220
220:   def self.warnonce(msg)
221:     if msg and not msg.empty? and @@messages[msg].nil?
222:       @@messages[msg] = true
223:       Kernel.warn(msg)
224:     end
225:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.