Sha256: 979cdbf927a88dffefc1d6c6870a434a9b6a1900632eede0418fcfc132e3364b

Contents?: true

Size: 884 Bytes

Versions: 3

Compression:

Stored size: 884 Bytes

Contents

module Katello
  class RhsmFactImporter < ::StructuredFactImporter
    def fact_name_class
      Katello::RhsmFactName
    end

    def normalize(_facts)
      facts = super
      facts = change_separator(facts)
      add_compose_facts(facts)
    end

    def add_compose_facts(facts)
      additional_keys = []
      facts.each_key do |fact_name|
        parts = fact_name.split(RhsmFactName::SEPARATOR)
        additional_keys += parts[0..-2].reduce([]) { |memo, part| memo << [memo.last, part].compact.join(RhsmFactName::SEPARATOR) }
      end

      # add the facts hierarchy to facts hash
      additional_keys.uniq.each do |key|
        facts[key] = nil
      end
      facts
    end

    def change_separator(facts)
      to_ret = {}
      facts.each do |key, value|
        to_ret[key.split('.').join(RhsmFactName::SEPARATOR)] = value
      end
      to_ret
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katello-3.6.0.1.rc2 app/models/katello/rhsm_fact_importer.rb
katello-3.6.0.rc2 app/models/katello/rhsm_fact_importer.rb
katello-3.6.0.rc1 app/models/katello/rhsm_fact_importer.rb