Sha256: b5a695680cdc1890709a7b861fbf31f90566fdb1ccecb061908a5375c66163fd

Contents?: true

Size: 1.2 KB

Versions: 25

Compression:

Stored size: 1.2 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
        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

25 entries across 25 versions & 1 rubygems

Version Path
katello-3.3.0.1 app/models/katello/rhsm_fact_importer.rb
katello-3.3.0 app/models/katello/rhsm_fact_importer.rb
katello-3.3.0.rc2 app/models/katello/rhsm_fact_importer.rb
katello-3.3.0.rc1.1 app/models/katello/rhsm_fact_importer.rb
katello-3.3.0.rc1 app/models/katello/rhsm_fact_importer.rb
katello-3.2.1.1 app/models/katello/rhsm_fact_importer.rb
katello-3.2.1 app/models/katello/rhsm_fact_importer.rb
katello-3.2.0 app/models/katello/rhsm_fact_importer.rb
katello-3.2.0.rc3 app/models/katello/rhsm_fact_importer.rb
katello-3.2.0.rc2 app/models/katello/rhsm_fact_importer.rb
katello-3.2.0.rc1.1 app/models/katello/rhsm_fact_importer.rb
katello-3.2.0.rc1 app/models/katello/rhsm_fact_importer.rb
katello-3.1.0.1 app/models/katello/rhsm_fact_importer.rb
katello-3.1.0 app/models/katello/rhsm_fact_importer.rb
katello-3.1.0.rc2.1 app/models/katello/rhsm_fact_importer.rb
katello-3.0.2 app/models/katello/rhsm_fact_importer.rb
katello-3.1.0.rc1 app/models/katello/rhsm_fact_importer.rb
katello-3.0.1 app/models/katello/rhsm_fact_importer.rb
katello-3.0.0 app/models/katello/rhsm_fact_importer.rb
katello-3.0.0.rc7 app/models/katello/rhsm_fact_importer.rb