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.44 lib/facter/framework/core/fact_manager.rb
facter-4.0.43 lib/facter/framework/core/fact_manager.rb
facter-4.0.42 lib/facter/framework/core/fact_manager.rb
facter-4.0.41 lib/facter/framework/core/fact_manager.rb
facter-4.0.40 lib/facter/framework/core/fact_manager.rb
facter-4.0.39 lib/facter/framework/core/fact_manager.rb
facter-4.0.38 lib/facter/framework/core/fact_manager.rb
facter-4.0.37 lib/facter/framework/core/fact_manager.rb
facter-4.0.36 lib/facter/framework/core/fact_manager.rb
facter-4.0.35 lib/facter/framework/core/fact_manager.rb
facter-4.0.34 lib/facter/framework/core/fact_manager.rb
facter-4.0.33 lib/facter/framework/core/fact_manager.rb
facter-4.0.32 lib/facter/framework/core/fact_manager.rb
facter-4.0.31 lib/facter/framework/core/fact_manager.rb
facter-4.0.30 lib/facter/framework/core/fact_manager.rb
facter-4.0.29 lib/framework/core/fact_manager.rb
facter-4.0.28 lib/framework/core/fact_manager.rb
facter-4.0.26 lib/framework/core/fact_manager.rb
facter-4.0.25 lib/framework/core/fact_manager.rb
facter-4.0.24 lib/framework/core/fact_manager.rb