Module: PactBroker::Matrix::MatrixRowVerificationDatasetModule
- Defined in:
- lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb
Instance Method Summary collapse
-
#matching_only_selectors_as_provider(resolved_selectors) ⇒ Sequel::Dataset<MatrixRow>
Verifications for the provider versions matching the given selectors, where the consumers match the pacticipants in the given selectors.
-
#matching_only_selectors_as_provider_where_not_only_pacticipant_name_in_selector(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
Return verifications where the provider version is described by any of the resolved_selectors that specify more than just the pacticipant name, AND the consumer is described by any of the resolved selectors.
-
#matching_only_selectors_as_provider_where_only_pacticipant_name_in_selector(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
Return verifications where the provider is described by any of the resolved_selectors that only specify the pacticipant NAME, AND the consumer is described by any of the resolved selectors.
- #matching_selectors_as_provider_for_any_consumer(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
- #provider_criteria_for_selectors(resolved_selectors) ⇒ Array<Hash>
-
#where_provider_version_matches_selectors(resolved_selectors) ⇒ Sequel::Dataset<Verification>
Name-only selectors carry no version id — matching_selectors_as_provider_for_any_consumer passes its selectors unfiltered — so they filter on the provider pacticipant instead.
Instance Method Details
#matching_only_selectors_as_provider(resolved_selectors) ⇒ Sequel::Dataset<MatrixRow>
Verifications for the provider versions matching the given selectors, where the consumers match the pacticipants in the given selectors.
13 14 15 16 17 18 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 13 def matching_only_selectors_as_provider(resolved_selectors) [ matching_only_selectors_as_provider_where_only_pacticipant_name_in_selector(resolved_selectors), matching_only_selectors_as_provider_where_not_only_pacticipant_name_in_selector(resolved_selectors) ].compact.reduce(&:union) end |
#matching_only_selectors_as_provider_where_not_only_pacticipant_name_in_selector(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
Return verifications where the provider version is described by any of the resolved_selectors that specify more than just the pacticipant name, AND the consumer is described by any of the resolved selectors. If the selector uses any of the tag/branch/environment/latest attributes, we need to join to the versions table to identify the required verifications. Return nil if there are no resolved selectors where anything other than the pacticipant name is specified.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 53 def matching_only_selectors_as_provider_where_not_only_pacticipant_name_in_selector(resolved_selectors) all_pacticipant_ids = resolved_selectors.collect(&:pacticipant_id).uniq resolved_selectors_with_versions_specified = resolved_selectors.reject(&:only_pacticipant_name_specified?) if resolved_selectors_with_versions_specified.any? select_verification_columns_with_aliases .where_provider_version_matches_selectors(resolved_selectors_with_versions_specified) .where(consumer_id: all_pacticipant_ids) end end |
#matching_only_selectors_as_provider_where_only_pacticipant_name_in_selector(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
Return verifications where the provider is described by any of the resolved_selectors that only specify the pacticipant NAME, AND the consumer is described by any of the resolved selectors. If the original selector only specified the pacticipant name, we don't need to join to the versions table to identify the required verifications. Return nil if there are no resolved selectors where only the pacticipant name is specified.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 34 def matching_only_selectors_as_provider_where_only_pacticipant_name_in_selector(resolved_selectors) all_pacticipant_ids = resolved_selectors.collect(&:pacticipant_id).uniq pacticipant_ids_for_pacticipant_only_selectors = resolved_selectors.select(&:only_pacticipant_name_specified?).collect(&:pacticipant_id).uniq if pacticipant_ids_for_pacticipant_only_selectors.any? select_verification_columns_with_aliases .where(provider_id: pacticipant_ids_for_pacticipant_only_selectors) .where(consumer_id: all_pacticipant_ids) end end |
#matching_selectors_as_provider_for_any_consumer(resolved_selectors) ⇒ Sequel::Dataset<Verification>?
22 23 24 25 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 22 def matching_selectors_as_provider_for_any_consumer(resolved_selectors) select_verification_columns_with_aliases .where_provider_version_matches_selectors(resolved_selectors) end |
#provider_criteria_for_selectors(resolved_selectors) ⇒ Array<Hash>
83 84 85 86 87 88 89 90 91 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 83 def provider_criteria_for_selectors(resolved_selectors) name_only, with_versions = resolved_selectors.partition(&:only_pacticipant_name_specified?) table = self.model.table_name criteria = [] criteria << { Sequel[table][:provider_id] => name_only.collect(&:pacticipant_id).uniq } if name_only.any? criteria << { Sequel[table][:provider_version_id] => with_versions.collect(&:pacticipant_version_id).uniq } if with_versions.any? criteria end |
#where_provider_version_matches_selectors(resolved_selectors) ⇒ Sequel::Dataset<Verification>
Name-only selectors carry no version id — matching_selectors_as_provider_for_any_consumer passes its selectors unfiltered — so they filter on the provider pacticipant instead. That identifies the same rows, because a verification's provider_id is the pacticipant_id of its provider_version.
71 72 73 74 75 76 77 78 |
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 71 def where_provider_version_matches_selectors(resolved_selectors) if resolved_selectors.empty? raise ArgumentError.new("resolved_selectors must not be empty") end criteria = provider_criteria_for_selectors(resolved_selectors) where(criteria.size > 1 ? Sequel.|(*criteria) : criteria.first) end |