Sha256: 43ae4509dbeaa9d38cd5dd70e3c1adf6d174b425f759ccb6bc5221d5b29a2408

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

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

    def initialize(host, facts = {})
      super
      @facts = change_separator(@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

    def add_new_facts
      @facts.keys.each { |key| add_fact_name(key) }
      super
    end

    def add_fact_name(name, is_parent = false)
      begin
        parent_name = find_parent(name)
        parent_fact_name = add_fact_name(parent_name, true) if parent_name
        fact_name = RhsmFactName.where(:name => name).first_or_create! do |new_fact|
          new_fact.parent = parent_fact_name
          new_fact.compose = is_parent
        end
      rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
        retry
      end
      FactValue.create(:fact_name => fact_name, :value => nil, :host => @host) if is_parent
      fact_name
    end

    def find_parent(name)
      split = name.split(Katello::RhsmFactName::SEPARATOR)
      split[0..split.length - 2].join(Katello::RhsmFactName::SEPARATOR) if split.length > 1
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-3.4.1 app/models/katello/rhsm_fact_importer.rb
katello-3.4.0.2 app/models/katello/rhsm_fact_importer.rb
katello-3.4.0.1 app/models/katello/rhsm_fact_importer.rb
katello-3.3.2 app/models/katello/rhsm_fact_importer.rb
katello-3.4.0 app/models/katello/rhsm_fact_importer.rb
katello-3.4.0.rc2 app/models/katello/rhsm_fact_importer.rb
katello-3.4.0.rc1 app/models/katello/rhsm_fact_importer.rb
katello-3.3.1.1 app/models/katello/rhsm_fact_importer.rb
katello-3.3.1 app/models/katello/rhsm_fact_importer.rb