Sha256: 45e79e8d7e8828c135b8a19380756d28622508bdae2bf8e2e4f47b0cbb514323

Contents?: true

Size: 1.75 KB

Versions: 23

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Facter
  class FactLoader
    include Singleton

    attr_reader :internal_facts, :external_facts, :facts

    def initialize
      @log = Log.new(self)

      @internal_facts = []
      @external_facts = []
      @facts = []
    end

    def load(options)
      @internal_loader ||= InternalFactLoader.new
      @external_fact_loader ||= ExternalFactLoader.new

      @facts = []
      @external_facts = []
      load_internal_facts(options)
      load_external_facts(options)

      @facts
    end

    private

    def load_internal_facts(options)
      @log.debug('Loading internal facts')

      if options[:user_query] || options[:show_legacy]
        # if we have a user query, then we must search in core facts and legacy facts
        @log.debug('Loading all internal facts')
        @internal_facts = @internal_loader.facts
      else
        @log.debug('Load only core facts')
        @internal_facts = @internal_loader.core_facts
      end

      @internal_facts = block_facts(@internal_facts, options)
      @facts.concat(@internal_facts)
    end

    def load_external_facts(options)
      @log.debug('Loading external facts')
      if options[:custom_facts]
        @log.debug('Loading custom facts')
        @external_facts.concat(@external_fact_loader.custom_facts)
      end

      if options[:external_facts]
        @log.debug('Loading external facts')
        @external_facts.concat(@external_fact_loader.external_facts)
      end

      @facts.concat(@external_facts)
    end

    def block_facts(facts, options)
      blocked_facts = options[:blocked_facts] || []

      facts = facts.reject do |fact|
        blocked_facts.select { |blocked_fact| fact.name.match(/^#{blocked_fact}/) }.any?
      end

      facts
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
facter-4.0.30 lib/facter/framework/core/fact_loaders/fact_loader.rb
facter-4.0.29 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.28 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.26 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.25 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.24 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.23 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.22 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.21 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.20 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.19 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.18 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.17 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.16 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.15 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.14 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.13 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.12 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.11 lib/framework/core/fact_loaders/fact_loader.rb
facter-4.0.10.pre lib/framework/core/fact_loaders/fact_loader.rb