Sha256: dc7a2292802c0fc2447bc595878913cc5cd6ebb109e6ca2dba5f418da65e19c1

Contents?: true

Size: 890 Bytes

Versions: 31

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

module Facter
  class FactFilter
    def filter_facts!(resolved_facts, user_query)
      filter_legacy_facts!(resolved_facts) if user_query.empty?
      filter_blocked_legacy_facts!(resolved_facts)
      resolved_facts
    end

    private

    # This will filter out the legacy facts that should be blocked. Because some legacy facts are just aliases
    # to the core ones, even if they are blocked, facter will resolved them but they won't be displayed.

    def filter_blocked_legacy_facts!(facts)
      blocked_facts = Options[:blocked_facts] || []

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

    def filter_legacy_facts!(resolved_facts)
      return if Options[:show_legacy]

      resolved_facts.reject!(&:legacy?)
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/framework/core/fact_filter.rb
facter-4.9.0 lib/facter/framework/core/fact_filter.rb
facter-4.8.0 lib/facter/framework/core/fact_filter.rb
facter-4.7.1 lib/facter/framework/core/fact_filter.rb
facter-4.7.0 lib/facter/framework/core/fact_filter.rb
facter-4.6.1 lib/facter/framework/core/fact_filter.rb
facter-4.6.0 lib/facter/framework/core/fact_filter.rb
facter-4.5.2 lib/facter/framework/core/fact_filter.rb
facter-4.5.1 lib/facter/framework/core/fact_filter.rb
facter-4.5.0 lib/facter/framework/core/fact_filter.rb
facter-4.4.3 lib/facter/framework/core/fact_filter.rb
facter-4.4.2 lib/facter/framework/core/fact_filter.rb
facter-4.4.1 lib/facter/framework/core/fact_filter.rb
facter-4.4.0 lib/facter/framework/core/fact_filter.rb
facter-4.3.1 lib/facter/framework/core/fact_filter.rb
facter-4.3.0 lib/facter/framework/core/fact_filter.rb
facter-4.2.14 lib/facter/framework/core/fact_filter.rb
facter-4.2.13 lib/facter/framework/core/fact_filter.rb
facter-4.2.12 lib/facter/framework/core/fact_filter.rb
facter-4.2.11 lib/facter/framework/core/fact_filter.rb