Module: Facter
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/facter.rb,
lib/facter/util/values.rb,
lib/facter/application.rb
Overview
A util module for facter containing helper methods
Defined Under Namespace
Modules: Application, Manufacturer, Memory, NetMask, Util
Constant Summary
- FACTERVERSION =
'1.6.0'- GREEN =
"[0;32m"- RESET =
"[0m"- @@debug =
0- @@timing =
0- @@messages =
{}
Class Method Summary (collapse)
-
+ (Object) [](name)
Return a fact object by name.
-
+ (Object) add(name, options = {}, &block)
Add a resolution mechanism for a named fact.
-
+ (Object) clear
Clear all facts.
-
+ (Object) collection
module methods.
-
+ (Object) debug(string)
Add some debugging.
-
+ (Object) debugging(bit)
Set debugging on or off.
- + (Boolean) debugging?
- + (Object) each
-
+ (Object) loadfacts
Load all of the default facts, and then everything from disk.
-
+ (Object) method_missing(name, *args)
Allow users to call fact names directly on the Facter class, either retrieving the value or comparing it to an existing value.
-
+ (Object) reset
Remove them all.
-
+ (Object) search(*dirs)
Register a directory to search through.
-
+ (Object) search_path
Return our registered search directories.
-
+ (Object) show_time(string)
show the timing information.
-
+ (Object) timing(bit)
Set timing on or off.
- + (Boolean) timing?
-
+ (Object) version
Return the version of the library.
- + (Object) warn(msg)
-
+ (Object) warnonce(msg)
Warn once.
Class Method Details
+ (Object) [](name)
Return a fact object by name. If you use this, you still have to call 'value' on it to retrieve the actual value.
90 91 92 |
# File 'lib/facter.rb', line 90 def self.[](name) collection.fact(name) end |
+ (Object) add(name, options = {}, &block)
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.
112 113 114 |
# File 'lib/facter.rb', line 112 def self.add(name, = {}, &block) collection.add(name, , &block) end |
+ (Object) clear
Clear all facts. Mostly used for testing.
157 158 159 160 |
# File 'lib/facter.rb', line 157 def self.clear Facter.flush Facter.reset end |
+ (Object) collection
module methods
53 54 55 56 57 58 |
# File 'lib/facter.rb', line 53 def self.collection unless defined?(@collection) and @collection @collection = Facter::Util::Collection.new end @collection end |
+ (Object) debug(string)
Add some debugging
66 67 68 69 70 71 72 73 |
# File 'lib/facter.rb', line 66 def self.debug(string) if string.nil? return end if self.debugging? puts GREEN + string + RESET end end |
+ (Object) debugging(bit)
Set debugging on or off.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/facter.rb', line 163 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 |
+ (Boolean) debugging?
75 76 77 |
# File 'lib/facter.rb', line 75 def self.debugging? @@debug != 0 end |
+ (Object) each
116 117 118 119 120 121 122 123 |
# File 'lib/facter.rb', line 116 def self.each # Make sure all facts are loaded. collection.load_all collection.each do |*args| yield(*args) end end |
+ (Object) loadfacts
Load all of the default facts, and then everything from disk.
226 227 228 |
# File 'lib/facter.rb', line 226 def self.loadfacts collection.load_all end |
+ (Object) method_missing(name, *args)
Allow users to call fact names directly on the Facter class, either retrieving the value or comparing it to an existing value.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/facter.rb', line 128 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 |
+ (Object) reset
Remove them all.
221 222 223 |
# File 'lib/facter.rb', line 221 def self.reset @collection = nil end |
+ (Object) search(*dirs)
Register a directory to search through.
233 234 235 |
# File 'lib/facter.rb', line 233 def self.search(*dirs) @search_path += dirs end |
+ (Object) search_path
Return our registered search directories.
238 239 240 |
# File 'lib/facter.rb', line 238 def self.search_path @search_path.dup end |
+ (Object) show_time(string)
show the timing information
80 81 82 |
# File 'lib/facter.rb', line 80 def self.show_time(string) puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing? end |
+ (Object) timing(bit)
Set timing on or off.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/facter.rb', line 189 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 |
+ (Boolean) timing?
84 85 86 |
# File 'lib/facter.rb', line 84 def self.timing? @@timing != 0 end |
+ (Object) version
Return the version of the library.
61 62 63 |
# File 'lib/facter.rb', line 61 def self.version return FACTERVERSION end |
+ (Object) warn(msg)
205 206 207 208 209 210 |
# File 'lib/facter.rb', line 205 def self.warn(msg) if Facter.debugging? and msg and not msg.empty? msg = [msg] unless msg.respond_to? :each msg.each { |line| Kernel.warn line } end end |
+ (Object) warnonce(msg)
Warn once.
213 214 215 216 217 218 |
# File 'lib/facter.rb', line 213 def self.warnonce(msg) if msg and not msg.empty? and @@messages[msg].nil? @@messages[msg] = true Kernel.warn(msg) end end |