class PactBroker::Matrix::Row::QueryHelper

Can't access other dataset_module methods from inside the Sequel `where{ … }` block, so make a private class with some helper methods

Public Class Methods

consumer_and_maybe_consumer_version_match_any_selector(selectors) click to toggle source
# File lib/pact_broker/matrix/row.rb, line 66
def self.consumer_and_maybe_consumer_version_match_any_selector(selectors)
  selectors.collect { |s| consumer_and_maybe_consumer_version_match_selector(s) }
end
consumer_and_maybe_consumer_version_match_selector(s) click to toggle source
# File lib/pact_broker/matrix/row.rb, line 70
def self.consumer_and_maybe_consumer_version_match_selector(s)
  if s[:pact_publication_ids]
    Sequel.&(pact_publication_id: s[:pact_publication_ids])
  elsif s[:pacticipant_version_id]
    Sequel.&(consumer_id: s[:pacticipant_id], consumer_version_id: s[:pacticipant_version_id])
  else
    Sequel.&(consumer_id: s[:pacticipant_id])
  end
end
either_consumer_or_provider_was_specified_in_query(selectors) click to toggle source

Some selecters are specified in the query, others are implied (when only one pacticipant is specified, the integrations are automatically worked out, and the selectors for these are of type :implied ) When there are 3 pacticipants that each have dependencies on each other (A->B, A->C, B->C), the query to deploy C (implied A, implied B, specified C) was returning the A->B row because it matched the implied selectors as well. This extra filter makes sure that every row that is returned actually matches one of the specified selectors.

# File lib/pact_broker/matrix/row.rb, line 111
def self.either_consumer_or_provider_was_specified_in_query(selectors)
  specified_pacticipant_ids = selectors.select{ |s| s[:type] == :specified }.collect{ |s| s[:pacticipant_id] }
  Sequel.|({ consumer_id: specified_pacticipant_ids } , { provider_id: specified_pacticipant_ids })
end
provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors) click to toggle source
# File lib/pact_broker/matrix/row.rb, line 96
def self.provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors)
  selectors.collect { |s|
    provider_and_maybe_provider_version_match_selector(s)
  } + selectors.collect { |s|
    provider_verification_is_missing_for_matching_selector(s)
  }
end
provider_and_maybe_provider_version_match_selector(s) click to toggle source
# File lib/pact_broker/matrix/row.rb, line 80
def self.provider_and_maybe_provider_version_match_selector(s)
  if s[:verification_ids]
    Sequel.&(verification_id: s[:verification_ids])
  elsif s[:pacticipant_version_id]
    Sequel.&(provider_id: s[:pacticipant_id], provider_version_id: s[:pacticipant_version_id])
  else
    Sequel.&(provider_id: s[:pacticipant_id])
  end
end
provider_verification_is_missing_for_matching_selector(s) click to toggle source

if the pact for a consumer version has never been verified, it exists in the matrix as a row with a blank provider version id

# File lib/pact_broker/matrix/row.rb, line 92
def self.provider_verification_is_missing_for_matching_selector(s)
  Sequel.&(provider_id: s[:pacticipant_id], provider_version_id: nil)
end