Module: PactBroker::Matrix::Service

Extended by:
Service, Repositories, Services
Included in:
Service
Defined in:
lib/pact_broker/matrix/service.rb

Instance Method Summary collapse

Methods included from Repositories

label_repository, matrix_repository, pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository

Methods included from Services

badge_service, certificate_service, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service

Instance Method Details

#find(selectors, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/pact_broker/matrix/service.rb', line 13

def find selectors, options = {}
  query_results = matrix_repository.find selectors, options
  deployment_status_summary = DeploymentStatusSummary.new(query_results.rows, query_results.resolved_selectors, query_results.integrations)
  QueryResultsWithDeploymentStatusSummary.new(query_results.rows, query_results.selectors, query_results.options, query_results.resolved_selectors, query_results.integrations, deployment_status_summary)
end

#find_compatible_pacticipant_versions(criteria) ⇒ Object



44
45
46
# File 'lib/pact_broker/matrix/service.rb', line 44

def find_compatible_pacticipant_versions criteria
  matrix_repository.find_compatible_pacticipant_versions criteria
end

#find_for_consumer_and_provider(params, options = {}) ⇒ Object



19
20
21
22
# File 'lib/pact_broker/matrix/service.rb', line 19

def find_for_consumer_and_provider params, options = {}
  selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] }]
  find(selectors, options)
end

#find_for_consumer_and_provider_with_tags(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pact_broker/matrix/service.rb', line 24

def find_for_consumer_and_provider_with_tags params
  consumer_criteria = {
    pacticipant_name: params[:consumer_name],
    tag: params[:tag],
    latest: true
  }
  provider_criteria = {
    pacticipant_name: params[:provider_name],
    tag: params[:provider_tag],
    latest: true
  }
  selectors = [consumer_criteria, provider_criteria]
  options = { latestby: 'cvpv' }
  if validate_selectors(selectors).empty?
    matrix_repository.find(selectors, options).first
  else
    nil
  end
end

#validate_selectors(selectors) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pact_broker/matrix/service.rb', line 48

def validate_selectors selectors
  error_messages = []

  selectors.each do | s |
    if s[:pacticipant_name].nil?
      error_messages << "Please specify the pacticipant name"
    else
      if s.key?(:pacticipant_version_number) && s.key?(:latest)
        error_messages << "A version number and latest flag cannot both be specified for #{s[:pacticipant_name]}"
      end
    end
  end

  selectors.collect{ |selector| selector[:pacticipant_name] }.compact.each do | pacticipant_name |
    unless pacticipant_service.find_pacticipant_by_name(pacticipant_name)
      error_messages << "Pacticipant #{pacticipant_name} not found"
    end
  end

  if selectors.size == 0
    error_messages << "Please provide 1 or more version selectors."
  end

  error_messages
end