class Facter::FactCollection
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/facter/models/fact_collection.rb, line 5 def initialize super @log = Log.new(self) end
Public Instance Methods
build_fact_collection!(facts)
click to toggle source
# File lib/facter/models/fact_collection.rb, line 10 def build_fact_collection!(facts) facts.each do |fact| next if %i[core legacy].include?(fact.type) && fact.value.nil? bury_fact(fact) end self end
bury(*args)
click to toggle source
# File lib/facter/models/fact_collection.rb, line 26 def bury(*args) raise ArgumentError, '2 or more arguments required' if args.count < 2 if args.count == 2 self[args[0]] = args[1] else arg = args.shift self[arg] = FactCollection.new unless self[arg] self[arg].bury(*args) unless args.empty? end self end
value(*keys)
click to toggle source
# File lib/facter/models/fact_collection.rb, line 20 def value(*keys) keys.reduce(self) do |memo, key| memo.fetch(key.to_s) end end
Private Instance Methods
bury_fact(fact)
click to toggle source
# File lib/facter/models/fact_collection.rb, line 42 def bury_fact(fact) split_fact_name = extract_fact_name(fact) bury(*split_fact_name + fact.filter_tokens << fact.value) rescue NoMethodError @log.error("#{fact.type.to_s.capitalize} fact `#{fact.name}` cannot be added to collection."\ ' The format of this fact is incompatible with other'\ " facts that belong to `#{fact.name.split('.').first}` group") end
extract_fact_name(fact)
click to toggle source
# File lib/facter/models/fact_collection.rb, line 51 def extract_fact_name(fact) fact.type == :legacy ? [fact.name] : fact.name.split('.') end