Sha256: d5db577c17dfb180775e03fdec3c57cb886e1a5c7393d8a5e64831c3f8b791fc

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'delegate'
require 'pact_broker/error'

module PactBroker
  module Pacts
    class VerifiablePact < SimpleDelegator
      attr_reader :selectors, :pending, :pending_provider_tags, :non_pending_provider_tags, :wip

      # TODO refactor this constructor
      def initialize(pact, selectors, pending, pending_provider_tags = [], non_pending_provider_tags = [], wip = false)
        super(pact)
        @pending = pending
        @selectors = selectors
        @pending_provider_tags = pending_provider_tags
        @non_pending_provider_tags = non_pending_provider_tags
        @wip = wip
      end

      def pending?
        pending
      end

      def wip?
        wip
      end

      def + other
        if pact_version_sha != other.pact_version_sha
          raise PactBroker::Error.new("Can't merge two verifiable pacts with different pact content")
        end

        latest_pact = [self, other].sort_by(&:consumer_version_order).last.__getobj__()

        VerifiablePact.new(
          latest_pact,
          selectors + other.selectors,
          pending || other.pending,
          pending_provider_tags + other.pending_provider_tags,
          non_pending_provider_tags + other.non_pending_provider_tags,
          wip || other.wip
        )
      end

      def <=> other
        if self.consumer_name != other.consumer_name
          return self.consumer_name <=> other.consumer_name
        else
          return self.consumer_version.order <=> other.consumer_version.order
        end
      end

      def consumer_version_order
        __getobj__().consumer_version.order
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-2.76.2 lib/pact_broker/pacts/verifiable_pact.rb
pact_broker-2.76.1 lib/pact_broker/pacts/verifiable_pact.rb