Skip to content

Commit

Permalink
refactor: make environment service extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 7, 2021
1 parent 7b903c1 commit e7c762d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/pact_broker/deployments/environment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,49 @@ module PactBroker
module Deployments
module EnvironmentService
using PactBroker::StringRefinements
extend self

def self.next_uuid
def self.included(base)
base.extend(self)
end

def next_uuid
SecureRandom.uuid
end

def self.create(uuid, environment)
def create(uuid, environment)
environment.uuid = uuid
if environment.display_name.blank?
environment.display_name = PactBroker::Pacticipants::GenerateDisplayName.call(environment.name)
end
environment.save
end

def self.update(uuid, environment)
def update(uuid, environment)
environment.uuid = uuid
if environment.display_name.blank?
environment.display_name = PactBroker::Pacticipants::GenerateDisplayName.call(environment.name)
end
environment.upsert
end

def self.find_all
def find_all
PactBroker::Deployments::Environment.order(Sequel.function(:lower, :display_name)).all
end

def self.find(uuid)
def find(uuid)
PactBroker::Deployments::Environment.where(uuid: uuid).single_record
end

def self.find_by_name(name)
def find_by_name(name)
PactBroker::Deployments::Environment.where(name: name).single_record
end

def self.delete(uuid)
def delete(uuid)
PactBroker::Deployments::Environment.where(uuid: uuid).delete
end

def self.find_for_pacticipant(_pacticipant)
def find_for_pacticipant(_pacticipant)
find_all
end
end
Expand Down

0 comments on commit e7c762d

Please sign in to comment.