Module: Facter
- Extended by:
- Core::Logging
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/facter.rb,
lib/facter/version.rb,
lib/facter/ec2/rest.rb,
lib/facter/util/posix.rb,
lib/facter/application.rb,
lib/facter/util/values.rb,
lib/facter/gce/metadata.rb,
lib/facter/processors/os.rb,
lib/facter/core/execution.rb,
lib/facter/util/file_read.rb,
lib/facter/util/formatter.rb,
lib/facter/util/processor.rb,
lib/facter/util/normalization.rb,
lib/facter/util/solaris_zones.rb,
lib/facter/core/directed_graph.rb,
lib/facter/util/nothing_loader.rb,
lib/facter/operatingsystem/base.rb,
lib/facter/util/operatingsystem.rb,
lib/facter/operatingsystem/linux.rb,
lib/facter/operatingsystem/sunos.rb,
lib/facter/operatingsystem/windows.rb,
lib/facter/operatingsystem/vmkernel.rb,
lib/facter/operatingsystem/cumuluslinux.rb,
lib/facter/operatingsystem/implementation.rb
Overview
Functions as a hash of ‘facts’ about your system system, such as MAC address, IP address, architecture, etc.
Defined Under Namespace
Modules: Application, Core, EC2, GCE, Manufacturer, Memory, NetMask, Operatingsystem, Processors, Util
Constant Summary collapse
- FACTERVERSION =
'2.3.0'
Constants included from Core::Logging
Core::Logging::GREEN, Core::Logging::RESET
Class Method Summary collapse
-
.[](name) ⇒ Facter::Util::Fact?
Returns a fact object by name.
-
.add(name, options = {}, { || ... }) ⇒ Facter::Util::Fact
Adds a resolution mechanism for a named fact.
-
.clear ⇒ void
Clears all cached values and removes all facts from memory.
-
.collection ⇒ Facter::Util::Collection
private
Accessor for the collection object which holds all the facts.
-
.define_fact(name, options = {}, &block) ⇒ Facter::Util::Fact
Define a new fact or extend an existing fact.
-
.each {|name, value| ... } ⇒ void
Iterates over fact names and values.
-
.fact(name) ⇒ Facter::Util::Fact?
Returns a fact object by name.
-
.flush ⇒ void
Flushes cached values for all facts.
-
.json? ⇒ Boolean
private
Returns whether the JSON “feature” is available.
-
.list ⇒ Array<String>
Lists all fact names.
-
.loadfacts ⇒ void
Loads all facts.
-
.reset ⇒ void
Removes all facts from memory.
-
.reset_search_path! ⇒ void
private
Reset the Facter search directories.
-
.search(*dirs) ⇒ void
Register directories to be searched for facts.
-
.search_external(dirs) ⇒ void
Registers directories to be searched for external facts.
-
.search_external_path ⇒ Array<String>
Returns the registered search directories.
-
.search_path ⇒ Array<String>
Returns the registered search directories.
-
.to_hash ⇒ Hash{String => Object}
Gets a hash mapping fact names to their values.
-
.value(name) ⇒ Object?
Gets the value for a fact.
-
.version ⇒ String
Returns the running version of Facter.
-
.version=(version) ⇒ void
private
Sets the Facter version.
Methods included from Core::Logging
clear_messages, debug, debugging, debugging?, debugonce, format_exception, log_exception, show_time, timing, timing?, trace, trace?, warn, warnonce
Class Method Details
.[](name) ⇒ Facter::Util::Fact?
Returns a fact object by name. If you use this, you still have to call ‘value` on it to retrieve the actual value.
81 82 83 |
# File 'lib/facter.rb', line 81 def self.[](name) collection.fact(name) end |
.add(name, options = {}, { || ... }) ⇒ Facter::Util::Fact
Adds 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.
160 161 162 |
# File 'lib/facter.rb', line 160 def self.add(name, = {}, &block) collection.add(name, , &block) end |
.clear ⇒ void
This method returns an undefined value.
Clears all cached values and removes all facts from memory.
186 187 188 189 |
# File 'lib/facter.rb', line 186 def self.clear Facter.flush Facter.reset end |
.collection ⇒ Facter::Util::Collection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Accessor for the collection object which holds all the facts
50 51 52 53 54 55 56 57 |
# File 'lib/facter.rb', line 50 def self.collection unless defined?(@collection) and @collection @collection = Facter::Util::Collection.new( Facter::Util::Loader.new, Facter::Util::Config.ext_fact_loader) end @collection end |
.define_fact(name, options = {}, &block) ⇒ Facter::Util::Fact
Define a new fact or extend an existing fact.
139 140 141 |
# File 'lib/facter.rb', line 139 def self.define_fact(name, = {}, &block) collection.define_fact(name, , &block) end |
.each {|name, value| ... } ⇒ void
This method returns an undefined value.
Iterates over fact names and values
172 173 174 175 176 177 178 179 |
# File 'lib/facter.rb', line 172 def self.each # Make sure all facts are loaded. collection.load_all collection.each do |*args| yield(*args) end end |
.fact(name) ⇒ Facter::Util::Fact?
Returns a fact object by name. If you use this, you still have to call ‘value` on it to retrieve the actual value.
86 87 88 |
# File 'lib/facter.rb', line 86 def self.fact(name) collection.fact(name) end |
.flush ⇒ void
This method returns an undefined value.
Flushes cached values for all facts. This does not cause code to be reloaded; it only clears the cached results.
96 97 98 |
# File 'lib/facter.rb', line 96 def self.flush collection.flush end |
.json? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the JSON “feature” is available.
62 63 64 65 66 67 68 69 |
# File 'lib/facter.rb', line 62 def self.json? begin require 'json' true rescue LoadError false end end |
.list ⇒ Array<String>
Lists all fact names
105 106 107 |
# File 'lib/facter.rb', line 105 def self.list collection.list end |
.loadfacts ⇒ void
This method returns an undefined value.
Loads all facts.
207 208 209 |
# File 'lib/facter.rb', line 207 def self.loadfacts collection.load_all end |
.reset ⇒ void
This method returns an undefined value.
Removes all facts from memory. Use this when the fact code has changed on disk and needs to be reloaded.
197 198 199 200 |
# File 'lib/facter.rb', line 197 def self.reset @collection = nil reset_search_path! end |
.reset_search_path! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Reset the Facter search directories.
236 237 238 |
# File 'lib/facter.rb', line 236 def self.reset_search_path! @search_path = [] end |
.search(*dirs) ⇒ void
This method returns an undefined value.
Register directories to be searched for facts. The registered directories must be absolute paths or they will be ignored.
219 220 221 |
# File 'lib/facter.rb', line 219 def self.search(*dirs) @search_path += dirs end |
.search_external(dirs) ⇒ void
This method returns an undefined value.
Registers directories to be searched for external facts.
249 250 251 |
# File 'lib/facter.rb', line 249 def self.search_external(dirs) Facter::Util::Config.external_facts_dirs += dirs end |
.search_external_path ⇒ Array<String>
Returns the registered search directories.
258 259 260 |
# File 'lib/facter.rb', line 258 def self.search_external_path Facter::Util::Config.external_facts_dirs.dup end |
.search_path ⇒ Array<String>
Returns the registered search directories.
228 229 230 |
# File 'lib/facter.rb', line 228 def self.search_path @search_path.dup end |
.to_hash ⇒ Hash{String => Object}
Gets a hash mapping fact names to their values
125 126 127 128 |
# File 'lib/facter.rb', line 125 def self.to_hash collection.load_all collection.to_hash end |
.value(name) ⇒ Object?
Gets the value for a fact. Returns ‘nil` if no such fact exists.
116 117 118 |
# File 'lib/facter.rb', line 116 def self.value(name) collection.value(name) end |
.version ⇒ String
Returns the running version of Facter.
55 56 57 58 59 60 61 62 |
# File 'lib/facter/version.rb', line 55 def self.version version_file = File.join(File.dirname(__FILE__), 'VERSION') return @facter_version if @facter_version if version = read_version_file(version_file) @facter_version = version end @facter_version ||= FACTERVERSION end |
.version=(version) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Sets the Facter version
69 70 71 |
# File 'lib/facter/version.rb', line 69 def self.version=(version) @facter_version = version end |