Class: Facter::FactCollection
- Inherits:
-
Hash
- Object
- Hash
- Facter::FactCollection
- Defined in:
- lib/models/fact_collection.rb
Instance Method Summary collapse
- #build_fact_collection!(facts) ⇒ Object
- #bury(*args) ⇒ Object
-
#initialize ⇒ FactCollection
constructor
A new instance of FactCollection.
- #value(*keys) ⇒ Object
Constructor Details
#initialize ⇒ FactCollection
Returns a new instance of FactCollection.
5 6 7 |
# File 'lib/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/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
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/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/models/fact_collection.rb', line 19 def value(*keys) keys.reduce(self) do |memo, key| memo.fetch(key.to_s) end end |