class PactBroker::Matrix::ResolvedSelector

Constants

NULL_PACTICIPANT_ID
NULL_VERSION_ID

A version ID of -1 will not match any rows, which is what we want to ensure that no matrix rows are returned for a version that does not exist.

Public Class Methods

for_non_existing_pacticipant(original_selector, type, ignore) click to toggle source

This is not possible for specified selectors, as there is validation at the HTTP query level to ensure that all pacticipants in the specified selectors exist. It is possible for the ignore selectors however.

# File lib/pact_broker/matrix/resolved_selector.rb, line 38
def self.for_non_existing_pacticipant(original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: NULL_PACTICIPANT_ID,
    pacticipant_name: original_selector[:pacticipant_name],
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end
for_pacticipant(pacticipant, original_selector, type, ignore) click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 25
def self.for_pacticipant(pacticipant, original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end
for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) click to toggle source

rubocop: enable Metrics/ParameterLists

# File lib/pact_broker/matrix/resolved_selector.rb, line 68
def self.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    pacticipant_version_id: NULL_VERSION_ID,
    pacticipant_version_number: original_selector[:pacticipant_version_number],
    latest: original_selector[:latest],
    tag: original_selector[:tag],
    branch: original_selector[:branch],
    main_branch: original_selector[:main_branch],
    environment_name: original_selector[:environment_name],
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end
for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) click to toggle source

rubocop: disable Metrics/ParameterLists

# File lib/pact_broker/matrix/resolved_selector.rb, line 49
def self.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    pacticipant_version_id: version.id,
    pacticipant_version_number: version.number,
    latest: original_selector[:latest],
    tag: original_selector[:tag],
    branch: original_selector[:branch] || (original_selector[:main_branch] ? version&.values[:branch_name] : nil),
    main_branch: original_selector[:main_branch],
    environment_name: original_selector[:environment_name],
    type: type,
    ignore: ignore,
    one_of_many: one_of_many,
    original_selector: original_selector
  )
end
new(params = {}) click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 21
def initialize(params = {})
  merge!(params)
end

Public Instance Methods

branch() click to toggle source

@return [String] the name of the branch

# File lib/pact_broker/matrix/resolved_selector.rb, line 114
def branch
  self[:branch]
end
consider?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 190
def consider?
  !ignore?
end
description() click to toggle source

rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength

# File lib/pact_broker/matrix/resolved_selector.rb, line 199
def description
  if latest_tagged? && pacticipant_version_number
    "the latest version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})"
  elsif latest_tagged?
    "the latest version of #{pacticipant_name} with tag #{tag} (no such version exists)"
  elsif latest_from_main_branch? && pacticipant_version_number.nil?
    "the latest version of #{pacticipant_name} from the main branch (no versions exist for this branch)"
  elsif main_branch? && pacticipant_version_number.nil?
    "any version of #{pacticipant_name} from the main branch (no versions exist for this branch)"
  elsif latest_from_branch? && pacticipant_version_number
    "the latest version of #{pacticipant_name} from branch #{branch} (#{pacticipant_version_number})"
  elsif latest_from_branch?
    "the latest version of #{pacticipant_name} from branch #{branch} (no such version exists)"
  elsif branch && pacticipant_version_number
    prefix = one_of_many? ? "one of the versions " : "the version "
    prefix + "of #{pacticipant_name} from branch #{branch} (#{pacticipant_version_number})"
  elsif branch
    "a version of #{pacticipant_name} from branch #{branch} (no such version exists)"
  elsif latest? && pacticipant_version_number
    "the latest version of #{pacticipant_name} (#{pacticipant_version_number})"
  elsif latest?
    "the latest version of #{pacticipant_name} (no such version exists)"
  elsif tag && pacticipant_version_number
    "a version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})"
  elsif tag
    "a version of #{pacticipant_name} with tag #{tag} (no such version exists)"
  elsif environment_name && pacticipant_version_number
    prefix = one_of_many? ? "one of the versions" : "the version"
    "#{prefix} of #{pacticipant_name} currently in #{environment_name} (#{pacticipant_version_number})"
  elsif environment_name
    "a version of #{pacticipant_name} currently in #{environment_name} (no version is currently recorded as deployed/released in this environment)"
  elsif pacticipant_version_number && version_does_not_exist?
    "version #{pacticipant_version_number} of #{pacticipant_name} (no such version exists)"
  elsif pacticipant_version_number
    "version #{pacticipant_version_number} of #{pacticipant_name}"
  elsif pacticipant_does_not_exist?
    "any version of #{pacticipant_name} (no such pacticipant exists)"
  else
    "any version of #{pacticipant_name}"
  end
end
environment_name() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 123
def environment_name
  self[:environment_name]
end
ignore?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 186
def ignore?
  self[:ignore]
end
inferred?() click to toggle source
Was this selector inferred based on the user's query?

(ie. the integrations were calculated because only one selector was specified)

# File lib/pact_broker/matrix/resolved_selector.rb, line 178
def inferred?
  self[:type] == :inferred
end
latest?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 105
def latest?
  self[:latest]
end
latest_from_branch?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 143
def latest_from_branch?
  latest? && branch
end
latest_from_main_branch?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 147
def latest_from_main_branch?
  latest? && main_branch?
end
latest_tagged?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 139
def latest_tagged?
  latest? && tag
end
main_branch?() click to toggle source

@return [Boolean]

# File lib/pact_broker/matrix/resolved_selector.rb, line 119
def main_branch?
  self[:main_branch]
end
most_specific_criterion() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 127
def most_specific_criterion
  if pacticipant_version_id
    { pacticipant_version_id: pacticipant_version_id }
  else
    { pacticipant_id: pacticipant_id }
  end
end
one_of_many?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 182
def one_of_many?
  self[:one_of_many]
end
only_pacticipant_name_specified?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 135
def only_pacticipant_name_specified?
  !!pacticipant_name && self[:original_selector].without(:pacticipant_name).none?{ |_key, value| value }
end
original_selector() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 194
def original_selector
  self[:original_selector]
end
pacticipant_does_not_exist?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 155
def pacticipant_does_not_exist?
  self[:pacticipant_id] == NULL_PACTICIPANT_ID
end
pacticipant_id() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 89
def pacticipant_id
  self[:pacticipant_id]
end
pacticipant_name() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 93
def pacticipant_name
  self[:pacticipant_name]
end
pacticipant_or_version_does_not_exist?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 151
def pacticipant_or_version_does_not_exist?
  pacticipant_does_not_exist? || version_does_not_exist?
end
pacticipant_version_id() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 97
def pacticipant_version_id
  self[:pacticipant_version_id]
end
pacticipant_version_number() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 101
def pacticipant_version_number
  self[:pacticipant_version_number]
end
pacticipant_version_specified_in_original_selector?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 85
def pacticipant_version_specified_in_original_selector?
  !!self.dig(:original_selector, :pacticipant_version_number)
end
specified?() click to toggle source

Did the user specify this selector in the user’s query?

# File lib/pact_broker/matrix/resolved_selector.rb, line 172
def specified?
  self[:type] == :specified
end
specified_version_that_does_not_exist?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 163
def specified_version_that_does_not_exist?
  specified? && version_does_not_exist?
end
tag() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 109
def tag
  self[:tag]
end
version_does_not_exist?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 159
def version_does_not_exist?
  !version_exists?
end
version_does_not_exist_description() click to toggle source

rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength

# File lib/pact_broker/matrix/resolved_selector.rb, line 242
def version_does_not_exist_description
  if version_does_not_exist?
    if tag
      "No version with tag #{tag} exists for #{pacticipant_name}"
    elsif branch
      "No version of #{pacticipant_name} from branch #{branch} exists"
    elsif main_branch?
      "No version of #{pacticipant_name} from the main branch exists"
    elsif environment_name
      "No version of #{pacticipant_name} is currently recorded as deployed or released in environment #{environment_name}"
    elsif pacticipant_version_number
      "No pacts or verifications have been published for version #{pacticipant_version_number} of #{pacticipant_name}"
    else
      "No pacts or verifications have been published for #{pacticipant_name}"
    end
  else
    ""
  end
end
version_exists?() click to toggle source
# File lib/pact_broker/matrix/resolved_selector.rb, line 167
def version_exists?
  pacticipant_version_id != NULL_VERSION_ID
end