Create a new fact, with no resolution mechanisms.
# File lib/facter/util/fact.rb, line 10 def initialize(name, options = {}) @name = name.to_s.downcase.intern # LAK:NOTE: This is slow for many options, but generally we won't have any and at # worst we'll have one. If we add more, this should be made more efficient. options.each do |name, value| case name when :ldapname; self.ldapname = value else raise ArgumentError, "Invalid fact option '%s'" % name end end @ldapname ||= @name.to_s @resolves = [] @searching = false @value = nil end
Add a new resolution mechanism. This requires a block, which will then be evaluated in the context of the new mechanism.
# File lib/facter/util/fact.rb, line 33 def add(value = nil, &block) begin resolve = Facter::Util::Resolution.new(@name) resolve.instance_eval(&block) if block @resolves << resolve resolve rescue => e Facter.warn "Unable to add resolve for #{@name}: #{e}" nil end end
Flush any cached values. If the resolver has a callback block defined using the on_flush DSL method, then invoke that block by sending a message to Resolution#flush.
# File lib/facter/util/fact.rb, line 51 def flush @resolves.each { |r| r.flush } @value = nil end
Return the value for a given fact. Searches through all of the mechanisms and returns either the first value or nil.
# File lib/facter/util/fact.rb, line 58 def value return @value if @value if @resolves.empty? Facter.debug "No resolves for %s" % @name return nil end searching do suitable_resolutions = sort_by_weight(find_suitable_resolutions(@resolves)) @value = find_first_real_value(suitable_resolutions) announce_when_no_suitable_resolution(suitable_resolutions) announce_when_no_value_found(@value) @value end end
Generated with the Darkfish Rdoc Generator 2.