Class: PactBroker::Services::PacticipantService

Inherits:
Object
  • Object
show all
Extended by:
Logging, Repositories, PactBroker::Services
Defined in:
lib/pact_broker/services/pacticipant_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, version_repository, webhook_repository

Methods included from PactBroker::Services

group_service, pact_service, pacticipant_service, tag_service, version_service, webhook_service

Methods included from Logging

included, logger, logger=

Class Method Details

.create(params) ⇒ Object



63
64
65
# File 'lib/pact_broker/services/pacticipant_service.rb', line 63

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

.delete(name) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/pact_broker/services/pacticipant_service.rb', line 67

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

.find_all_pacticipantsObject



36
37
38
# File 'lib/pact_broker/services/pacticipant_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/services/pacticipant_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



44
45
46
47
48
49
50
51
# File 'lib/pact_broker/services/pacticipant_service.rb', line 44

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/services/pacticipant_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



53
54
55
# File 'lib/pact_broker/services/pacticipant_service.rb', line 53

def self.find_relationships
  pact_repository.find_latest_pacts.collect{ | pact| PactBroker::Domain::Relationship.create pact.consumer, pact.provider }
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/services/pacticipant_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



78
79
80
# File 'lib/pact_broker/services/pacticipant_service.rb', line 78

def self.pacticipant_names
  pacticipant_repository.pacticipant_names
end

.update(params) ⇒ Object



57
58
59
60
61
# File 'lib/pact_broker/services/pacticipant_service.rb', line 57

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