Sha256: cebd328529f909a37a1a72a1f6a5f0f5d8b01fd916eae6a97694007d37ad09f5

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

module PactBroker
  module Domain

    class Relationship

      attr_reader :consumer, :provider

      def initialize consumer, provider
        @consumer = consumer
        @provider = provider
      end

      def self.create consumer, provider
        new consumer, provider
      end

      def eq? other
        Relationship === other && other.consumer == consumer && other.provider == provider
      end

      def == other
        eq?(other)
      end

      def consumer_name
        consumer.name
      end

      def provider_name
        provider.name
      end

      def pacticipants
        [consumer, provider]
      end

      def connected? other
        (self.to_a & other.to_a).any?
      end

      def include? pacticipant
        pacticipant.id == consumer.id || pacticipant.id == provider.id
      end

      def <=> other
        comp = consumer_name <=> other.consumer_name
        return comp unless comp == 0
        provider_name <=> other.provider_name
      end

      def to_s
        "Relationship between #{consumer_name} and #{provider_name}"
      end

      def to_a
        [consumer, provider]
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pact_broker-1.9.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.9.0.rc1 lib/pact_broker/domain/relationship.rb
pact_broker-1.8.1 lib/pact_broker/domain/relationship.rb
pact_broker-1.8.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.7.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.6.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.5.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.4.0 lib/pact_broker/domain/relationship.rb
pact_broker-1.3.2.rc1 lib/pact_broker/domain/relationship.rb