Class: PactBroker::Versions::EagerLoaders::LatestVersionForBranch
- Inherits:
-
Object
- Object
- PactBroker::Versions::EagerLoaders::LatestVersionForBranch
- Defined in:
- lib/pact_broker/versions/eager_loaders.rb
Class Method Summary collapse
- .call(eo, **other) ⇒ Object
- .group_by_pacticipant_id(versions) ⇒ Object
- .initialize_association(versions) ⇒ Object
- .latest_versions_for_pacticipant_branches(pacticipant_id, branches, version_class) ⇒ Object
- .populate_associations(versions) ⇒ Object
- .populate_associations_by_pacticipant(pacticipant_id, versions) ⇒ Object
- .populate_versions_with_branches(versions, latest_versions_for_branches) ⇒ Object
Class Method Details
.call(eo, **other) ⇒ Object
5 6 7 8 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 5 def self.call(eo, **other) initialize_association(eo[:rows]) populate_associations(eo[:rows]) end |
.group_by_pacticipant_id(versions) ⇒ Object
20 21 22 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 20 def self.group_by_pacticipant_id(versions) versions.to_a.group_by(&:pacticipant_id) end |
.initialize_association(versions) ⇒ Object
10 11 12 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 10 def self.initialize_association(versions) versions.each{|version| version.associations[:latest_version_for_branch] = nil } end |
.latest_versions_for_pacticipant_branches(pacticipant_id, branches, version_class) ⇒ Object
39 40 41 42 43 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 39 def self.latest_versions_for_pacticipant_branches(pacticipant_id, branches, version_class) version_class.latest_versions_for_pacticipant_branches(pacticipant_id, branches).each_with_object({}) do | row, hash | hash[[row.pacticipant_id, row.branch]] = row end end |
.populate_associations(versions) ⇒ Object
14 15 16 17 18 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 14 def self.populate_associations(versions) group_by_pacticipant_id(versions).each do | pacticipant, versions | populate_associations_by_pacticipant(pacticipant, versions) end end |
.populate_associations_by_pacticipant(pacticipant_id, versions) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 24 def self.populate_associations_by_pacticipant(pacticipant_id, versions) latest_versions_for_branches = latest_versions_for_pacticipant_branches( pacticipant_id, versions.collect(&:branch).uniq.compact, versions.first.class ) self.populate_versions_with_branches(versions, latest_versions_for_branches) end |
.populate_versions_with_branches(versions, latest_versions_for_branches) ⇒ Object
33 34 35 36 37 |
# File 'lib/pact_broker/versions/eager_loaders.rb', line 33 def self.populate_versions_with_branches(versions, latest_versions_for_branches) versions.select(&:branch).each do | version | version.associations[:latest_version_for_branch] = latest_versions_for_branches[[version.pacticipant_id, version.branch]] end end |