Module: RFacter::DSL::Facter

Defined in:
lib/rfacter/dsl.rb

Overview

TODO:

Implement reset

TODO:

Implement search

DSL for top-level Facter methods

Since:

  • 0.1.0

Defined Under Namespace

Modules: Core, Util

Class Method Summary collapse

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.

Parameters:

  • name (String, Symbol)

    the name of the fact

Returns:

Since:

  • 0.1.0



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.

Parameters:

  • name (String)

    the fact name

  • options (Hash) (defaults to: {})

    optional parameters for the fact - attributes of Util::Fact and RFacter::DSL::Facter::Util::Resolution can be supplied here

  • block (Proc)

    a block defining a fact resolution

Options Hash (options):

  • :timeout (Integer)

    set the timeout for this resolution

Returns:

Since:

  • 0.1.0



69
70
71
# File 'lib/rfacter/dsl.rb', line 69

def self.add(name, options = {}, &block)
  COLLECTION.value.add(name, options, &block)
end

.clearvoid

This method returns an undefined value.

Clears all cached values and removes all facts from memory.

Since:

  • 0.1.0



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

Parameters:

  • msg (String)

    the debug message

Since:

  • 0.1.0



86
87
88
# File 'lib/rfacter/dsl.rb', line 86

def self.debug(msg)
  ::RFacter::Config.config.logger.debug(msg)
end

.debugonce(msg) ⇒ void

Note:

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.

Parameters:

  • msg (String)

    the debug message

Since:

  • 0.1.0



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.

Parameters:

  • name (Symbol)

    The name of the fact to define

  • options (Hash) (defaults to: {})

    A hash of options to set on the fact

Returns:

See Also:

Since:

  • 0.1.0



109
110
111
# File 'lib/rfacter/dsl.rb', line 109

def self.define_fact(name, options = {}, &block)
  COLLECTION.value.define_fact(name, options, &block)
end

.each {|name, value| ... } ⇒ void

This method returns an undefined value.

Iterates over fact names and values

Yield Parameters:

  • name (String)

    the fact name

  • value (String)

    the current value of the fact

Since:

  • 0.1.0



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.

Parameters:

  • name (String, Symbol)

    the name of the fact

Returns:

Since:

  • 0.1.0



126
127
128
# File 'lib/rfacter/dsl.rb', line 126

def self.fact(name)
  COLLECTION.value.fact(name)
end

.flushvoid

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.

Since:

  • 0.1.0



134
135
136
# File 'lib/rfacter/dsl.rb', line 134

def self.flush
  COLLECTION.value.flush
end

.listArray<String>

Lists all fact names

Returns:

  • (Array<String>)

    array of fact names

Since:

  • 0.1.0



141
142
143
# File 'lib/rfacter/dsl.rb', line 141

def self.list
  COLLECTION.value.list
end

.loadfactsvoid

This method returns an undefined value.

Loads all facts.

Since:

  • 0.1.0



148
149
150
# File 'lib/rfacter/dsl.rb', line 148

def self.loadfacts
  COLLECTION.value.load_all
end

.log_exception(exception, message = nil) ⇒ Object

Since:

  • 0.1.0



152
153
154
# File 'lib/rfacter/dsl.rb', line 152

def self.log_exception(exception, message = nil)
  ::RFacter::Config.config.logger.log_exception(exception, messge)
end

.resetvoid

Note:

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.

Since:

  • 0.1.0



163
164
# File 'lib/rfacter/dsl.rb', line 163

def self.reset
end

.search(*dirs) ⇒ void

Note:

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.

Parameters:

  • dirs (String)

    directories to search

Since:

  • 0.1.0



175
176
# File 'lib/rfacter/dsl.rb', line 175

def self.search(*dirs)
end

.search_pathArray<String>

Returns the registered search directories.

Returns:

  • (Array<String>)

    An array of the directories searched

Since:

  • 0.1.0



181
182
183
# File 'lib/rfacter/dsl.rb', line 181

def self.search_path
  COLLECTION.value.search_path
end

.to_hashHash{String => Object}

Gets a hash mapping fact names to their values.

Returns:

  • (Hash{String => Object})

    the hash of fact names and values

Since:

  • 0.1.0



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.

Parameters:

  • name (String, Symbol)

    the fact name

Returns:

  • (Object, nil)

    the value of the fact, or nil if no fact is found

Since:

  • 0.1.0



198
199
200
# File 'lib/rfacter/dsl.rb', line 198

def self.value(name)
  COLLECTION.value.value(name)
end

.versionString

Returns the current RFacter version

Returns:

  • (String)

Since:

  • 0.1.0



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.

Parameters:

  • msg (String)

    the warning message to be printed

Since:

  • 0.1.0



215
216
217
# File 'lib/rfacter/dsl.rb', line 215

def self.warn(msg)
  ::RFacter::Config.config.logger.warn(msg)
end

.warnonce(msg) ⇒ void

Note:

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.

Parameters:

  • msg (String)

    the warning message to be printed

Since:

  • 0.1.0



230
231
232
# File 'lib/rfacter/dsl.rb', line 230

def self.warnonce(msg)
  ::RFacter::Config.config.logger.warnonce(msg)
end