Class: PactBroker::Versions::EagerLoaders::LatestVersionForPacticipant

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/versions/eager_loaders.rb

Class Method Summary collapse

Class Method Details

.call(eo, **_other) ⇒ Object



5
6
7
# File 'lib/pact_broker/versions/eager_loaders.rb', line 5

def self.call(eo, **_other)
  populate_associations(eo[:rows])
end

.group_by_pacticipant(versions) ⇒ Object



15
16
17
# File 'lib/pact_broker/versions/eager_loaders.rb', line 15

def self.group_by_pacticipant(versions)
  versions.to_a.group_by(&:pacticipant)
end

.populate_associations(versions) ⇒ Object



9
10
11
12
13
# File 'lib/pact_broker/versions/eager_loaders.rb', line 9

def self.populate_associations(versions)
  group_by_pacticipant(versions).each do | pacticipant, participant_versions |
    populate_associations_by_pacticipant(pacticipant, participant_versions)
  end
end

.populate_associations_by_pacticipant(pacticipant, versions) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/pact_broker/versions/eager_loaders.rb', line 19

def self.populate_associations_by_pacticipant(pacticipant, versions)
  latest_version = versions.first.class.latest_version_for_pacticipant(pacticipant).single_record

  versions.each do | version |
    version.associations[:latest_version_for_pacticipant] = latest_version
  end
end