Sha256: 696b0c3f9323ab0ab0c0c69e9656f4eb8940e02433164dc58faf1ebb0135e122

Contents?: true

Size: 1.79 KB

Versions: 25

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Facter
  class FactManager
    include Singleton

    def initialize
      @internal_fact_mgr = InternalFactManager.new
      @external_fact_mgr = ExternalFactManager.new
      @fact_loader = FactLoader.instance
      @log = Log.new(self)
    end

    def searched_facts(user_query = [])
      loaded_facts = @fact_loader.load(Options.get)
      QueryParser.parse(user_query, loaded_facts)
    end

    def resolve_facts(user_query = [])
      loaded_facts = @fact_loader.load(Options.get)
      searched_facts = QueryParser.parse(user_query, loaded_facts)

      cache_manager = Facter::CacheManager.new
      searched_facts, cached_facts = cache_manager.resolve_facts(searched_facts)
      internal_facts = @internal_fact_mgr.resolve_facts(searched_facts)
      external_facts = @external_fact_mgr.resolve_facts(searched_facts)

      resolved_facts = override_core_facts(internal_facts, external_facts)

      cache_manager.cache_facts(resolved_facts)
      resolved_facts = resolved_facts.concat(cached_facts)

      FactFilter.new.filter_facts!(resolved_facts)

      resolved_facts
    end

    def resolve_core(user_query = [])
      loaded_facts_hash = @fact_loader.internal_facts

      searched_facts = QueryParser.parse(user_query, loaded_facts_hash)
      resolved_facts = @internal_fact_mgr.resolve_facts(searched_facts)
      FactFilter.new.filter_facts!(resolved_facts)

      resolved_facts
    end

    private

    def override_core_facts(core_facts, custom_facts)
      return core_facts unless custom_facts

      custom_facts.each do |custom_fact|
        core_facts.delete_if { |core_fact| root_fact_name(core_fact) == custom_fact.name }
      end

      core_facts + custom_facts
    end

    def root_fact_name(fact)
      fact.name.split('.').first
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
facter-4.0.23 lib/framework/core/fact_manager.rb
facter-4.0.22 lib/framework/core/fact_manager.rb
facter-4.0.21 lib/framework/core/fact_manager.rb
facter-4.0.20 lib/framework/core/fact_manager.rb
facter-4.0.19 lib/framework/core/fact_manager.rb