Class: Katello::ContentUnitIndexer::RepoAssociationTracker

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/content_unit_indexer.rb

Instance Method Summary collapse

Constructor Details

#initialize(content_type, service_class, repository) ⇒ RepoAssociationTracker

Returns a new instance of RepoAssociationTracker.



80
81
82
83
84
85
# File 'app/services/katello/content_unit_indexer.rb', line 80

def initialize(content_type, service_class, repository)
  @values = {}
  @content_type = content_type
  @repository = repository
  @service_class = service_class
end

Instance Method Details

#db_valuesObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/services/katello/content_unit_indexer.rb', line 102

def db_values
  return @final_values if @final_values
  @final_value = []

  @final_values = ::Katello::ContentUnitIndexer.pulp_id_to_id_map(@content_type, @values.keys).map do |pulp_id, katello_id|
    #:repository_id => X, :erratum_id => y
    row = {:repository_id => @repository.id, @content_type.model_class.unit_id_field => katello_id}
    row[pulp_href_association_name] = @values[pulp_id] if pulp_href_association_name
    row
  end
  ContentUnitIndexer.insert_timestamps(@content_type.model_class, @final_values)
  @final_values
end

#pulp_href_association_nameObject



116
117
118
# File 'app/services/katello/content_unit_indexer.rb', line 116

def pulp_href_association_name
  'erratum_pulp3_href' if @content_type.label == 'erratum'
end

#push(unit) ⇒ Object

pulp_href is only provided if we’re storing a different ‘pulp_id’ on the repo association



92
93
94
95
96
97
98
99
100
# File 'app/services/katello/content_unit_indexer.rb', line 92

def push(unit)
  if @service_class.backend_unit_identifier
    pulp_href = unit.dig(@service_class.backend_unit_identifier)
  else
    pulp_href = nil
  end
  unit_id = unit[@service_class.unit_identifier]
  @values[unit_id] = pulp_href
end

#unit_idsObject



87
88
89
# File 'app/services/katello/content_unit_indexer.rb', line 87

def unit_ids
  db_values.map { |row| row[@content_type.model_class.unit_id_field] }
end