Module: RFacter::DSL::Facter
- Defined in:
- lib/rfacter/dsl.rb
Overview
Implement reset
Implement search
DSL for top-level Facter methods
Defined Under Namespace
Class Method Summary collapse
-
.[](name) ⇒ RFacter::Util::Fact?
Returns a fact object by name.
-
.add(name, options = {}, { || ... }) ⇒ RFacter::Util::Fact
Adds a resolution mechanism for a named fact.
-
.clear ⇒ void
Clears all cached values and removes all facts from memory.
-
.debug(msg) ⇒ void
Prints a debug message if debugging is turned on.
-
.debugonce(msg) ⇒ void
Prints a debug message only once.
-
.define_fact(name, options = {}, &block) ⇒ RFacter::Util::Fact
Define a new fact or extend an existing fact.
-
.each {|name, value| ... } ⇒ void
Iterates over fact names and values.
-
.fact(name) ⇒ RFacter::Util::Fact?
Returns a fact object by name.
-
.flush ⇒ void
Flushes cached values for all facts.
-
.list ⇒ Array<String>
Lists all fact names.
-
.loadfacts ⇒ void
Loads all facts.
- .log_exception(exception, message = nil) ⇒ Object
-
.reset ⇒ void
Removes all facts from memory.
-
.search(*dirs) ⇒ void
Register directories to be searched for facts.
-
.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 current RFacter version.
-
.warn(msg) ⇒ void
Prints a warning message.
-
.warnonce(msg) ⇒ void
Prints a warning message only once per process.
Class Method Details
.[](name) ⇒ RFacter::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.
50 51 52 |
# File 'lib/rfacter/dsl.rb', line 50 def self.[](name) COLLECTION.value.fact(name) end |
.add(name, options = {}, { || ... }) ⇒ RFacter::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.
69 70 71 |
# File 'lib/rfacter/dsl.rb', line 69 def self.add(name, = {}, &block) COLLECTION.value.add(name, , &block) end |
.clear ⇒ void
This method returns an undefined value.
Clears all cached values and removes all facts from memory.
76 77 78 79 |
# File 'lib/rfacter/dsl.rb', line 76 def self.clear self.flush self.reset end |
.debug(msg) ⇒ void
This method returns an undefined value.
Prints a debug message if debugging is turned on
86 87 88 |
# File 'lib/rfacter/dsl.rb', line 86 def self.debug(msg) ::RFacter::Config.config.logger.debug(msg) end |
.debugonce(msg) ⇒ void
Uniqueness is based on the string, not the specific location of the method call.
This method returns an undefined value.
Prints a debug message only once.
97 98 99 |
# File 'lib/rfacter/dsl.rb', line 97 def self.debugonce(msg) ::RFacter::Config.config.logger.debugonce(msg) end |
.define_fact(name, options = {}, &block) ⇒ RFacter::Util::Fact
Define a new fact or extend an existing fact.
109 110 111 |
# File 'lib/rfacter/dsl.rb', line 109 def self.define_fact(name, = {}, &block) COLLECTION.value.define_fact(name, , &block) end |
.each {|name, value| ... } ⇒ void
This method returns an undefined value.
Iterates over fact names and values
119 120 121 122 123 |
# File 'lib/rfacter/dsl.rb', line 119 def self.each COLLECTION.value.each do |*args| yield(*args) end end |
.fact(name) ⇒ RFacter::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.
126 127 128 |
# File 'lib/rfacter/dsl.rb', line 126 def self.fact(name) COLLECTION.value.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.
134 135 136 |
# File 'lib/rfacter/dsl.rb', line 134 def self.flush COLLECTION.value.flush end |
.list ⇒ Array<String>
Lists all fact names
141 142 143 |
# File 'lib/rfacter/dsl.rb', line 141 def self.list COLLECTION.value.list end |
.loadfacts ⇒ void
This method returns an undefined value.
Loads all facts.
148 149 150 |
# File 'lib/rfacter/dsl.rb', line 148 def self.loadfacts COLLECTION.value.load_all end |
.log_exception(exception, message = nil) ⇒ Object
152 153 154 |
# File 'lib/rfacter/dsl.rb', line 152 def self.log_exception(exception, = nil) ::RFacter::Config.config.logger.log_exception(exception, messge) end |
.reset ⇒ void
This is currently a no-op for RFacter pending changes to how collections are handled.
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.
163 164 |
# File 'lib/rfacter/dsl.rb', line 163 def self.reset end |
.search(*dirs) ⇒ void
This is currently a no-op for RFacter pending changes to how collections are handled.
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.
175 176 |
# File 'lib/rfacter/dsl.rb', line 175 def self.search(*dirs) end |
.search_path ⇒ Array<String>
Returns the registered search directories.
181 182 183 |
# File 'lib/rfacter/dsl.rb', line 181 def self.search_path COLLECTION.value.search_path end |
.to_hash ⇒ Hash{String => Object}
Gets a hash mapping fact names to their values.
188 189 190 |
# File 'lib/rfacter/dsl.rb', line 188 def self.to_hash COLLECTION.value.to_hash end |
.value(name) ⇒ Object?
Gets the value for a fact.
198 199 200 |
# File 'lib/rfacter/dsl.rb', line 198 def self.value(name) COLLECTION.value.value(name) end |
.version ⇒ String
Returns the current RFacter version
205 206 207 |
# File 'lib/rfacter/dsl.rb', line 205 def self.version RFacter::VERSION end |
.warn(msg) ⇒ void
This method returns an undefined value.
Prints a warning message. The message is only printed if debugging is enabled.
215 216 217 |
# File 'lib/rfacter/dsl.rb', line 215 def self.warn(msg) ::RFacter::Config.config.logger.warn(msg) end |
.warnonce(msg) ⇒ void
Unlike warn the message will be printed even if debugging is not turned on. This behavior is likely to change and should not be relied on.
This method returns an undefined value.
Prints a warning message only once per process. Each unique string is printed once.
230 231 232 |
# File 'lib/rfacter/dsl.rb', line 230 def self.warnonce(msg) ::RFacter::Config.config.logger.warnonce(msg) end |