Sha256: 6b3e97ae1783fbdf1a2bc78c51a25214813bd414249da88b00636a9066e00963

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require "pact_broker/deployments/environment"
require "securerandom"
require "pact_broker/pacticipants/generate_display_name"
require "pact_broker/string_refinements"

module PactBroker
  module Deployments
    module EnvironmentService
      using PactBroker::StringRefinements
      extend self

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

      def next_uuid
        SecureRandom.uuid
      end

      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 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 find_all
        PactBroker::Deployments::Environment.order(Sequel.function(:lower, :display_name)).all
      end

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

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

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

      def find_for_pacticipant(_pacticipant)
        find_all
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact_broker-2.86.0 lib/pact_broker/deployments/environment_service.rb
pact_broker-2.85.1 lib/pact_broker/deployments/environment_service.rb
pact_broker-2.85.0 lib/pact_broker/deployments/environment_service.rb
pact_broker-2.84.0 lib/pact_broker/deployments/environment_service.rb