Sha256: 4ec04e5dadab40dcf4cdafbddc625da64e0124cc0ddacc11068f9a2f17633239

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Facter
  module FactAugmenter
    def self.augment_resolved_facts(searched_facts, resolved_facts)
      augumented_resolved_facts = []
      searched_facts.each do |searched_fact|
        matched_facts = get_resolved_facts_for_searched_fact(searched_fact, resolved_facts)
        augment_resolved_fact_for_user_query!(searched_fact, matched_facts)
        augumented_resolved_facts.concat(matched_facts)
      end

      augumented_resolved_facts
    end

    private_class_method def self.get_resolved_facts_for_searched_fact(searched_fact, resolved_facts)
      if searched_fact.name.include?('.*')
        resolved_facts
          .select { |resolved_fact| resolved_fact.name.match(searched_fact.name) }
          .reject(&:user_query)
          .uniq(&:name)
      else
        resolved_facts
          .select { |resolved_fact| searched_fact.name.eql?(resolved_fact.name) }
          .reject(&:user_query)
          .uniq(&:name)
      end
    end

    private_class_method def self.augment_resolved_fact_for_user_query!(searched_fact, matched_facts)
      matched_facts.each do |matched_fact|
        matched_fact.user_query = searched_fact.user_query
        matched_fact.filter_tokens = searched_fact.filter_tokens
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facter-4.0.52 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.51 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.50 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.49 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.48 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.47 lib/facter/framework/core/fact_augmenter.rb
facter-4.0.46 lib/facter/framework/core/fact_augmenter.rb