Manage which facts exist and how we access them. Largely just a wrapper around a hash of facts.
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/util/collection.rb, line 10 10: def [](name) 11: value(name) 12: 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/util/collection.rb, line 16 16: def add(name, options = {}, &block) 17: name = canonize(name) 18: 19: unless fact = @facts[name] 20: fact = Facter::Util::Fact.new(name) 21: 22: @facts[name] = fact 23: end 24: 25: # Set any fact-appropriate options. 26: options.each do |opt, value| 27: method = opt.to_s + "=" 28: if fact.respond_to?(method) 29: fact.send(method, value) 30: options.delete(opt) 31: end 32: end 33: 34: if block_given? and resolve = fact.add(&block) 35: # If the resolve was actually added, set any resolve-appropriate options 36: options.each do |opt, value| 37: method = opt.to_s + "=" 38: if resolve.respond_to?(method) 39: resolve.send(method, value) 40: options.delete(opt) 41: end 42: end 43: end 44: 45: unless options.empty? 46: raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",") 47: end 48: 49: return fact 50: end
Iterate across all of the facts.
# File lib/facter/util/collection.rb, line 55 55: def each 56: @facts.each do |name, fact| 57: value = fact.value 58: unless value.nil? 59: yield name.to_s, value 60: end 61: end 62: end
Return a fact by name.
# File lib/facter/util/collection.rb, line 65 65: def fact(name) 66: name = canonize(name) 67: 68: # Try to load the fact if necessary 69: loader.load(name) unless @facts[name] 70: 71: # Try HARDER 72: loader.load_all unless @facts[name] 73: 74: @facts[name] 75: end
Flush all cached values.
# File lib/facter/util/collection.rb, line 78 78: def flush 79: @facts.each { |name, fact| fact.flush } 80: end
Return a list of all of the facts.
# File lib/facter/util/collection.rb, line 87 87: def list 88: return @facts.keys 89: end
Load all known facts.
# File lib/facter/util/collection.rb, line 92 92: def load_all 93: loader.load_all 94: end
The thing that loads facts if we don’t have them.
# File lib/facter/util/collection.rb, line 97 97: def loader 98: unless defined?(@loader) 99: @loader = Facter::Util::Loader.new 100: end 101: @loader 102: end
Return a hash of all of our facts.
# File lib/facter/util/collection.rb, line 105 105: def to_hash 106: @facts.inject({}) do |h, ary| 107: value = ary[1].value 108: if ! value.nil? 109: # For backwards compatibility, convert the fact name to a string. 110: h[ary[0].to_s] = value 111: end 112: h 113: end 114: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.