Class: Katello::RhsmFactImporter
- Inherits:
-
FactImporter
- Object
- FactImporter
- Katello::RhsmFactImporter
- Defined in:
- app/models/katello/rhsm_fact_importer.rb
Instance Method Summary collapse
- #add_fact_name(name, is_parent = false) ⇒ Object
- #add_new_facts ⇒ Object
- #change_separator(facts) ⇒ Object
- #fact_name_class ⇒ Object
- #find_parent(name) ⇒ Object
-
#initialize(host, facts = {}) ⇒ RhsmFactImporter
constructor
A new instance of RhsmFactImporter.
Constructor Details
#initialize(host, facts = {}) ⇒ RhsmFactImporter
Returns a new instance of RhsmFactImporter.
7 8 9 10 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 7 def initialize(host, facts = {}) super @facts = change_separator(@facts) end |
Instance Method Details
#add_fact_name(name, is_parent = false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 25 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 |
#add_new_facts ⇒ Object
20 21 22 23 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 20 def add_new_facts @facts.keys.each { |key| add_fact_name(key) } super end |
#change_separator(facts) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 12 def change_separator(facts) to_ret = {} facts.each do |key, value| to_ret[key.split('.').join(RhsmFactName::SEPARATOR)] = value end to_ret end |
#fact_name_class ⇒ Object
3 4 5 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 3 def fact_name_class Katello::RhsmFactName end |
#find_parent(name) ⇒ Object
40 41 42 43 |
# File 'app/models/katello/rhsm_fact_importer.rb', line 40 def find_parent(name) split = name.split(Katello::RhsmFactName::SEPARATOR) split[0..split.length - 2].join(Katello::RhsmFactName::SEPARATOR) if split.length > 1 end |