Class: PactBroker::Domain::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/domain/relationship.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, provider) ⇒ Relationship

Returns a new instance of Relationship.



8
9
10
11
# File 'lib/pact_broker/domain/relationship.rb', line 8

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

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



6
7
8
# File 'lib/pact_broker/domain/relationship.rb', line 6

def consumer
  @consumer
end

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/pact_broker/domain/relationship.rb', line 6

def provider
  @provider
end

Class Method Details

.create(consumer, provider) ⇒ Object



13
14
15
# File 'lib/pact_broker/domain/relationship.rb', line 13

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

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
48
49
# File 'lib/pact_broker/domain/relationship.rb', line 45

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

#==(other) ⇒ Object



21
22
23
# File 'lib/pact_broker/domain/relationship.rb', line 21

def == other
  eq?(other)
end

#connected?(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pact_broker/domain/relationship.rb', line 37

def connected? other
  include?(other.consumer) || include?(other.provider)
end

#consumer_nameObject



25
26
27
# File 'lib/pact_broker/domain/relationship.rb', line 25

def consumer_name
  consumer.name
end

#eq?(other) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pact_broker/domain/relationship.rb', line 17

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

#include?(pacticipant) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pact_broker/domain/relationship.rb', line 41

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

#pacticipantsObject



33
34
35
# File 'lib/pact_broker/domain/relationship.rb', line 33

def pacticipants
  [consumer, provider]
end

#provider_nameObject



29
30
31
# File 'lib/pact_broker/domain/relationship.rb', line 29

def provider_name
  provider.name
end

#to_aObject



55
56
57
# File 'lib/pact_broker/domain/relationship.rb', line 55

def to_a
  [consumer, provider]
end

#to_sObject



51
52
53
# File 'lib/pact_broker/domain/relationship.rb', line 51

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