Module: PactBroker::Matrix::MatrixRowVerificationDatasetModule

Defined in:
lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb

Instance Method Summary collapse

Instance Method Details

#inner_join_versions_for_selectors_as_provider(resolved_selectors) ⇒ Sequel::Dataset<Verification>

Don’t think it’s worth splitting this into 2 different queries for selectors with only pacticipant name/selectors with version properties, as it’s unlikely for there ever to be a query through the UI or CLI that results in 1 selector which only has a pacticipant name in it.

Parameters:

Returns:

  • (Sequel::Dataset<Verification>)


70
71
72
73
74
75
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 70

def inner_join_versions_for_selectors_as_provider(resolved_selectors)
  # get the UnresolvedSelector objects back out of the resolved_selectors because the Version.for_selector() method uses the UnresolvedSelector
  unresolved_selectors = resolved_selectors.collect(&:original_selector).uniq
  versions = PactBroker::Domain::Version.ids_for_selectors(unresolved_selectors)
  join_versions_dataset(versions)
end

#join_versions_dataset(versions_dataset) ⇒ Object



78
79
80
# File 'lib/pact_broker/matrix/matrix_row_verification_dataset_module.rb', line 78

def join_versions_dataset(versions_dataset)
  join(versions_dataset, { Sequel[self.model.table_name][:provider_version_id] => Sequel[:versions][:id] }, table_alias: :versions)
end

#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.

Parameters:

Returns:



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.

Parameters:

Returns:

  • (Sequel::Dataset<Verification>, nil)


53
54
55
56
57
58
59
60
61
62
63
# 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)
  # get the UnresolvedSelector objects back out of the resolved_selectors because the Version.for_selector() method uses the UnresolvedSelector
  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
      .inner_join_versions_for_selectors_as_provider(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.

Parameters:

Returns:

  • (Sequel::Dataset<Verification>, nil)


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>?

Returns:

  • (Sequel::Dataset<Verification>, nil)


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
    .inner_join_versions_for_selectors_as_provider(resolved_selectors)
end