Sha256: 6cff8ac015e3d239cbfe97d22a606594ba59bdb1084efc95e18c54cb88114989

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'pact_broker/repositories'

module PactBroker

  module Services
    module PactService

      extend self

      extend PactBroker::Repositories

      def find_pact params
        if params[:consumer_version_number] == 'latest'
          pact_repository.find_latest_pact(params[:consumer_name], params[:provider_name])
        else
          pact_repository.find_pact(params[:consumer_name], params[:consumer_version_number], params[:provider_name])
        end
      end

      def find_latest_pacts
        pact_repository.find_latest_pacts
      end

      def create_or_update_pact params
        provider = pacticipant_repository.find_by_name_or_create params[:provider_name]
        consumer = pacticipant_repository.find_by_name_or_create params[:consumer_name]
        version = version_repository.find_by_pacticipant_id_and_number_or_create consumer.id, params[:consumer_version_number]

        if pact = pact_repository.find_by_version_and_provider(version.id, provider.id)
          pact.update(json_content: params[:json_content])
          return pact, false
        else
          pact = pact_repository.create json_content: params[:json_content], version_id: version.id, provider_id: provider.id
          return pact, true
        end

      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-1.0.0.alpha1 lib/pact_broker/services/pact_service.rb
pact_broker-0.0.10 lib/pact_broker/services/pact_service.rb
pact_broker-0.0.9 lib/pact_broker/services/pact_service.rb