Class: PactBroker::Tags::EagerLoaders::HeadTag
- Inherits:
-
Object
- Object
- PactBroker::Tags::EagerLoaders::HeadTag
- Defined in:
- lib/pact_broker/tags/eager_loaders.rb
Class Method Summary collapse
- .call(eo, **_other) ⇒ Object
- .group_by_pacticipant_id(tags) ⇒ Object
- .initialize_association(tags) ⇒ Object
- .latest_tags_for_pacticipant_id(pacticipant_id, tag_names, tag_class) ⇒ Object
- .populate_associations(tags) ⇒ Object
- .populate_associations_by_pacticipant(pacticipant_id, tags) ⇒ Object
- .populate_tags(tags, latest_tags_for_tags) ⇒ Object
Class Method Details
.call(eo, **_other) ⇒ Object
5 6 7 8 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 5 def self.call(eo, **_other) initialize_association(eo[:rows]) populate_associations(eo[:rows]) end |
.group_by_pacticipant_id(tags) ⇒ Object
20 21 22 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 20 def self.group_by_pacticipant_id() .to_a.group_by(&:pacticipant_id) end |
.initialize_association(tags) ⇒ Object
10 11 12 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 10 def self.initialize_association() .each{|tag| tag.associations[:head_tag] = nil } end |
.latest_tags_for_pacticipant_id(pacticipant_id, tag_names, tag_class) ⇒ Object
39 40 41 42 43 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 39 def self.(pacticipant_id, tag_names, tag_class) tag_class.(pacticipant_id, tag_names).each_with_object({}) do | tag, hash | hash[[tag.pacticipant_id, tag.name]] = tag end end |
.populate_associations(tags) ⇒ Object
14 15 16 17 18 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 14 def self.populate_associations() group_by_pacticipant_id().each do | pacticipant_id, | populate_associations_by_pacticipant(pacticipant_id, ) end end |
.populate_associations_by_pacticipant(pacticipant_id, tags) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 24 def self.populate_associations_by_pacticipant(pacticipant_id, ) = ( pacticipant_id, .collect(&:name).uniq.compact, .first.class ) self.(, ) end |
.populate_tags(tags, latest_tags_for_tags) ⇒ Object
33 34 35 36 37 |
# File 'lib/pact_broker/tags/eager_loaders.rb', line 33 def self.(, ) .each do | tag | tag.associations[:head_tag] = [[tag.pacticipant_id, tag.name]] end end |