Class: PactBroker::Deployments::ReleasedVersionService

Inherits:
Object
  • Object
show all
Extended by:
Events::Publisher, Repositories::Scopes
Defined in:
lib/pact_broker/deployments/released_version_service.rb

Class Method Summary collapse

Methods included from Repositories::Scopes

scope_for, unscoped, with_no_scope

Class Method Details

.create_or_update(uuid_for_new_released_version, version, environment) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pact_broker/deployments/released_version_service.rb', line 19

def self.create_or_update(uuid_for_new_released_version, version, environment)
  released_version = ReleasedVersion.new(
    uuid: uuid_for_new_released_version,
    version: version,
    pacticipant_id: version.pacticipant_id,
    environment: environment
  ).insert_ignore
  # Can't reproduce it in a test, but am getting a "Attempt to update object did not result in a single row modification"
  # error when marking an existing row as supported again IRL.
  ReleasedVersion.where(id: released_version.id).set_currently_supported
  released_version.refresh
  broadcast(:released_version_created, { released_version: released_version })
  released_version
end

.find_by_uuid(uuid) ⇒ Object



15
16
17
# File 'lib/pact_broker/deployments/released_version_service.rb', line 15

def self.find_by_uuid(uuid)
  ReleasedVersion.where(uuid: uuid).single_record
end

.find_currently_supported_versions_for_environment(environment, pacticipant_name: nil, pacticipant_version_number: nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/pact_broker/deployments/released_version_service.rb', line 34

def self.find_currently_supported_versions_for_environment(environment, pacticipant_name: nil, pacticipant_version_number: nil)
  query = ReleasedVersion
    .currently_supported
    .for_environment(environment)
  query = query.for_pacticipant_name(pacticipant_name) if pacticipant_name
  query = query.for_pacticipant_version_number(pacticipant_version_number) if pacticipant_version_number
  query.all
end

.find_currently_supported_versions_for_pacticipant(pacticipant) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/pact_broker/deployments/released_version_service.rb', line 53

def self.find_currently_supported_versions_for_pacticipant(pacticipant)
  scope_for(ReleasedVersion)
    .currently_supported
    .where(pacticipant_id: pacticipant.id)
    .eager(:version)
    .eager(:environment)
    .order(:created_at, :id)
    .all
end

.find_released_version_for_version_and_environment(version, environment) ⇒ Object



43
44
45
46
47
# File 'lib/pact_broker/deployments/released_version_service.rb', line 43

def self.find_released_version_for_version_and_environment(version, environment)
  ReleasedVersion
    .for_version_and_environment(version, environment)
    .single_record
end

.next_uuidObject



11
12
13
# File 'lib/pact_broker/deployments/released_version_service.rb', line 11

def self.next_uuid
  SecureRandom.uuid
end

.record_version_support_ended(released_version) ⇒ Object



49
50
51
# File 'lib/pact_broker/deployments/released_version_service.rb', line 49

def self.record_version_support_ended(released_version)
  released_version.record_support_ended
end