Class: PactBroker::Matrix::Repository

Inherits:
Object
  • Object
show all
Includes:
Repositories, Repositories::Helpers
Defined in:
lib/pact_broker/matrix/repository.rb

Constant Summary collapse

TP_COLS =

TODO move latest verification logic in to database

PactBroker::Matrix::Row::TP_COLS
GROUP_BY_PROVIDER_VERSION_NUMBER =
[:consumer_name, :consumer_version_number, :provider_name, :provider_version_number]
GROUP_BY_PROVIDER =
[:consumer_name, :consumer_version_number, :provider_name]
GROUP_BY_PACT =
[:consumer_name, :provider_name]

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 Repositories::Helpers

#case_sensitivity_options, #mysql?, #name_like, #order_ignore_case, #postgres?, #select_all_qualified, #select_for_subquery, #upsert

Instance Method Details

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

Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pact_broker/matrix/repository.rb', line 55

def find specified_selectors, options = {}
  resolved_selectors = resolve_selectors(specified_selectors, options)
  lines = query_matrix(resolved_selectors, options)
  lines = apply_latestby(options, specified_selectors, lines)

  # This needs to be done after the latestby, so can't be done in the db unless
  # the latestby logic is moved to the db
  if options.key?(:success)
    lines = lines.select{ |l| options[:success].include?(l.success) }
  end

  integrations = find_integrations_for_specified_selectors(resolved_selectors.select(&:specified?))
  QueryResults.new(lines.sort, specified_selectors, options, resolved_selectors, integrations)
end

#find_compatible_pacticipant_versions(selectors) ⇒ Object



76
77
78
# File 'lib/pact_broker/matrix/repository.rb', line 76

def find_compatible_pacticipant_versions selectors
  find(selectors, latestby: 'cvpv').select{|line| line.success }
end

#find_for_consumer_and_provider(pacticipant_1_name, pacticipant_2_name) ⇒ Object



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

def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
  selectors = [{ pacticipant_name: pacticipant_1_name }, { pacticipant_name: pacticipant_2_name }]
  options = { latestby: 'cvpv' }
  find(selectors, options)
end

#find_ids_for_pacticipant_names(params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pact_broker/matrix/repository.rb', line 30

def find_ids_for_pacticipant_names params
  criteria  = {}

  if params[:consumer_name] || params[:provider_name]
    if params[:consumer_name]
      pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:consumer_name])).single_record
      criteria[:consumer_id] = pacticipant.id if pacticipant
    end

    if params[:provider_name]
      pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:provider_name])).single_record
      criteria[:provider_id] = pacticipant.id if pacticipant
    end
  end

  if params[:pacticipant_name]
    pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:pacticipant_name])).single_record
    criteria[:pacticipant_id] = pacticipant.id if pacticipant
  end

  criteria[:tag_name] = params[:tag_name] if params[:tag_name].is_a?(String) # Could be a sym from resource parameters in api.rb
  criteria
end

#find_integrations_for_specified_selectors(resolved_specified_selectors) ⇒ Object

If one pacticipant is specified, find all the integrations that involve that pacticipant If two or more are specified, just return the integrations that involve the specified pacticipants



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pact_broker/matrix/repository.rb', line 82

def find_integrations_for_specified_selectors(resolved_specified_selectors)
  specified_pacticipant_names = resolved_specified_selectors.collect(&:pacticipant_name)
  QuickRow
    .select(:consumer_name, :consumer_id, :provider_name, :provider_id)
    .matching_selectors(resolved_specified_selectors)
    .distinct
    .all
    .collect do |row |
      row.to_hash
    end
    .uniq
    .collect do | hash |
      required = is_a_row_for_this_integration_required?(specified_pacticipant_names, hash[:consumer_name])
      Integration.from_hash(hash.merge(required: required))
    end
end