Class: Facter::FactCollection

Inherits:
Hash
  • Object
show all
Defined in:
lib/facter/models/fact_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeFactCollection

Returns a new instance of FactCollection.



5
6
7
# File 'lib/facter/models/fact_collection.rb', line 5

def initialize
  super
end

Instance Method Details

#build_fact_collection!(facts) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/facter/models/fact_collection.rb', line 9

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) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/facter/models/fact_collection.rb', line 25

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) ⇒ Object



19
20
21
22
23
# File 'lib/facter/models/fact_collection.rb', line 19

def value(*keys)
  keys.reduce(self) do |memo, key|
    memo.fetch(key.to_s)
  end
end