| Module | Facter |
| In: |
lib/facter.rb
|
| FACTERVERSION | = | '1.5.4' |
| GREEN | = | "[0;32m" |
| RESET | = | "[0m" |
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 78
78: def self.[](name)
79: collection.fact(name)
80: 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 100
100: def self.add(name, options = {}, &block)
101: collection.add(name, options, &block)
102: end
Clear all facts. Mostly used for testing.
# File lib/facter.rb, line 145
145: def self.clear
146: Facter.flush
147: Facter.reset
148: end
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
Set debugging on or off.
# File lib/facter.rb, line 151
151: def self.debugging(bit)
152: if bit
153: case bit
154: when TrueClass; @@debug = 1
155: when FalseClass; @@debug = 0
156: when Fixnum
157: if bit > 0
158: @@debug = 1
159: else
160: @@debug = 0
161: end
162: when String;
163: if bit.downcase == 'off'
164: @@debug = 0
165: else
166: @@debug = 1
167: end
168: else
169: @@debug = 0
170: end
171: else
172: @@debug = 0
173: end
174: end
# File lib/facter.rb, line 104
104: def self.each
105: # Make sure all facts are loaded.
106: collection.load_all
107:
108: collection.each do |*args|
109: yield(*args)
110: end
111: end
Load all of the default facts, and then everything from disk.
# File lib/facter.rb, line 182
182: def self.loadfacts
183: collection.load_all
184: 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 116
116: def method_missing(name, *args)
117: question = false
118: if name.to_s =~ /\?$/
119: question = true
120: name = name.to_s.sub(/\?$/,'')
121: end
122:
123: if fact = @collection.fact(name)
124: if question
125: value = fact.value.downcase
126: args.each do |arg|
127: if arg.to_s.downcase == value
128: return true
129: end
130: end
131:
132: # If we got this far, there was no match.
133: return false
134: else
135: return fact.value
136: end
137: else
138: # Else, fail like a normal missing method.
139: raise NoMethodError, "Could not find fact '%s'" % name
140: end
141: end