Class: PactBroker::Pacticipants::Service

Inherits:
Object
  • Object
show all
Extended by:
Logging, Repositories, Services
Defined in:
lib/pact_broker/pacticipants/service.rb

Constant Summary

Constants included from Logging

Logging::LOG_DIR, Logging::LOG_FILE_NAME

Class Method Summary collapse

Methods included from Repositories

pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository

Methods included from Services

group_service, pact_service, pacticipant_service, tag_service, verification_service, version_service, webhook_service

Methods included from Logging

included, log_error, logger, logger=

Class Method Details

.create(params) ⇒ Object



71
72
73
# File 'lib/pact_broker/pacticipants/service.rb', line 71

def self.create params
  pacticipant_repository.create(params)
end

.delete(name) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pact_broker/pacticipants/service.rb', line 75

def self.delete name
  pacticipant = find_pacticipant_by_name name
  connection = PactBroker::Domain::Pacticipant.new.db
  select_pacticipant = "select id from pacticipants where name = '#{name}'"
  connection.run("delete from tags where version_id IN (select id from versions where pacticipant_id = #{pacticipant.id})")
  connection.run("delete from pact_publications where consumer_version_id IN (select id from versions where pacticipant_id = #{pacticipant.id})")
  connection.run("delete from pact_publications where provider_id = #{pacticipant.id}")
  connection.run("delete from verifications where pact_version_id IN (select id from pact_versions where provider_id = #{pacticipant.id})")
  connection.run("delete from verifications where pact_version_id IN (select id from pact_versions where consumer_id = #{pacticipant.id})")
  connection.run("delete from pact_versions where provider_id = #{pacticipant.id}")
  connection.run("delete from pact_versions where consumer_id = #{pacticipant.id}")
  connection.run("delete from versions where pacticipant_id = #{pacticipant.id}")
  webhook_service.delete_by_pacticipant pacticipant
  connection.run("delete from pacticipants where id = #{pacticipant.id}")
end

.find_all_pacticipant_versions_in_reverse_order(name) ⇒ Object



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

def self.find_all_pacticipant_versions_in_reverse_order name
  pacticipant_repository.find_all_pacticipant_versions_in_reverse_order(name)
end

.find_all_pacticipantsObject



36
37
38
# File 'lib/pact_broker/pacticipants/service.rb', line 36

def self.find_all_pacticipants
  pacticipant_repository.find_all
end

.find_pacticipant_by_name(name) ⇒ Object



40
41
42
# File 'lib/pact_broker/pacticipants/service.rb', line 40

def self.find_pacticipant_by_name name
  pacticipant_repository.find_by_name(name)
end

.find_pacticipant_repository_url_by_pacticipant_name(name) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/pact_broker/pacticipants/service.rb', line 48

def self.find_pacticipant_repository_url_by_pacticipant_name name
  pacticipant = pacticipant_repository.find_by_name(name)
  if pacticipant && pacticipant.repository_url
    pacticipant.repository_url
  else
    nil
  end
end

.find_potential_duplicate_pacticipants(pacticipant_name) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/pact_broker/pacticipants/service.rb', line 27

def self.find_potential_duplicate_pacticipants pacticipant_name
  PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames
    .call(pacticipant_name, pacticipant_names).tap { | names|
      if names.any?
        logger.info "The following potential duplicate pacticipants were found for #{pacticipant_name}: #{names.join(", ")}"
      end
    } .collect{ | name | pacticipant_repository.find_by_name(name) }
end

.find_relationshipsObject



57
58
59
60
61
62
63
# File 'lib/pact_broker/pacticipants/service.rb', line 57

def self.find_relationships
  pact_repository.find_latest_pacts
    .collect do | pact|
      latest_verification = verification_service.find_latest_verification_for(pact.consumer, pact.provider)
      PactBroker::Domain::Relationship.create pact.consumer, pact.provider, pact, latest_verification
    end
end

.messages_for_potential_duplicate_pacticipants(pacticipant_names, base_url) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/pact_broker/pacticipants/service.rb', line 16

def self.messages_for_potential_duplicate_pacticipants pacticipant_names, base_url
  messages = []
  pacticipant_names.each do | name |
    potential_duplicate_pacticipants = find_potential_duplicate_pacticipants(name)
    if potential_duplicate_pacticipants.any?
      messages << Messages.potential_duplicate_pacticipant_message(name, potential_duplicate_pacticipants, base_url)
    end
  end
  messages
end

.pacticipant_namesObject



91
92
93
# File 'lib/pact_broker/pacticipants/service.rb', line 91

def self.pacticipant_names
  pacticipant_repository.pacticipant_names
end

.update(params) ⇒ Object



65
66
67
68
69
# File 'lib/pact_broker/pacticipants/service.rb', line 65

def self.update params
  pacticipant = pacticipant_repository.find_by_name(params.fetch(:name))
  pacticipant.update(params)
  pacticipant_repository.find_by_name(params.fetch(:name))
end