Sha256: 3e0470be7d6ce3b830a48b654e8b69d627da23a5e303dafb22447e79deb84c41

Contents?: true

Size: 865 Bytes

Versions: 29

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module Facter
  class FactCollection < Hash
    def initialize
      super
    end

    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

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

    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

    private

    def bury_fact(fact)
      bury(*fact.name.split('.') + fact.filter_tokens << fact.value)
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
facter-4.0.46 lib/facter/models/fact_collection.rb
facter-4.0.44 lib/facter/models/fact_collection.rb
facter-4.0.43 lib/facter/models/fact_collection.rb
facter-4.0.42 lib/facter/models/fact_collection.rb
facter-4.0.41 lib/facter/models/fact_collection.rb
facter-4.0.40 lib/facter/models/fact_collection.rb
facter-4.0.39 lib/facter/models/fact_collection.rb
facter-4.0.38 lib/facter/models/fact_collection.rb
facter-4.0.37 lib/facter/models/fact_collection.rb
facter-4.0.36 lib/facter/models/fact_collection.rb
facter-4.0.35 lib/facter/models/fact_collection.rb
facter-4.0.34 lib/facter/models/fact_collection.rb
facter-4.0.33 lib/facter/models/fact_collection.rb
facter-4.0.32 lib/facter/models/fact_collection.rb
facter-4.0.31 lib/facter/models/fact_collection.rb
facter-4.0.30 lib/facter/models/fact_collection.rb
facter-4.0.29 lib/models/fact_collection.rb
facter-4.0.28 lib/models/fact_collection.rb
facter-4.0.26 lib/models/fact_collection.rb
facter-4.0.25 lib/models/fact_collection.rb