Class: PactBroker::Pacticipants::Service

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

Constant Summary

Constants included from Services

Services::FACTORIES

Class 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, get, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, register_default_services, register_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service

Methods included from Logging

included, #log_error

Class Method Details

.create(params) ⇒ Object



76
77
78
# File 'lib/pact_broker/pacticipants/service.rb', line 76

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

.delete(name) ⇒ Object



80
81
82
83
84
# File 'lib/pact_broker/pacticipants/service.rb', line 80

def self.delete name
  pacticipant = find_pacticipant_by_name name
  webhook_service.delete_all_webhhook_related_objects_by_pacticipant(pacticipant)
  pacticipant.destroy
end

.delete_if_orphan(pacticipant) ⇒ Object



86
87
88
# File 'lib/pact_broker/pacticipants/service.rb', line 86

def self.delete_if_orphan(pacticipant)
  pacticipant_repository.delete_if_orphan(pacticipant)
end

.find(options) ⇒ Object



51
52
53
# File 'lib/pact_broker/pacticipants/service.rb', line 51

def self.find options
  pacticipant_repository.find options
end

.find_all_pacticipant_versions_in_reverse_order(name, pagination_options = nil) ⇒ Object



55
56
57
# File 'lib/pact_broker/pacticipants/service.rb', line 55

def self.find_all_pacticipant_versions_in_reverse_order name, pagination_options = nil
  pacticipant_repository.find_all_pacticipant_versions_in_reverse_order(name, pagination_options)
end

.find_all_pacticipantsObject



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

def self.find_all_pacticipants
  pacticipant_repository.find_all
end

.find_by_id(id) ⇒ Object



47
48
49
# File 'lib/pact_broker/pacticipants/service.rb', line 47

def self.find_by_id id
  pacticipant_repository.find_by_id(id)
end

.find_pacticipant_by_name(name) ⇒ Object



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

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

.find_pacticipant_by_name!(name) ⇒ Object



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

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

.find_pacticipant_repository_url_by_pacticipant_name(name) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/pact_broker/pacticipants/service.rb', line 59

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



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

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

.messages_for_potential_duplicate_pacticipants(pacticipant_names, base_url) ⇒ Object



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

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



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

def self.pacticipant_names
  pacticipant_repository.pacticipant_names
end

.update(params) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/pact_broker/pacticipants/service.rb', line 68

def self.update params
  # TODO move this to the repository!
  pacticipant = pacticipant_repository.find_by_name(params.fetch('name'))
  PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
  pacticipant.save
  pacticipant_repository.find_by_name(params.fetch('name'))
end