Class: PactBroker::Matrix::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/matrix/integration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer_id, consumer_name, provider_id, provider_name, required) ⇒ Integration

Returns a new instance of Integration.



14
15
16
17
18
19
20
# File 'lib/pact_broker/matrix/integration.rb', line 14

def initialize consumer_id, consumer_name, provider_id, provider_name, required
  @consumer_id = consumer_id
  @consumer_name = consumer_name
  @provider_id = provider_id
  @provider_name = provider_name
  @required = required
end

Instance Attribute Details

#consumer_idObject (readonly)

Returns the value of attribute consumer_id.



12
13
14
# File 'lib/pact_broker/matrix/integration.rb', line 12

def consumer_id
  @consumer_id
end

#consumer_nameObject (readonly)

Returns the value of attribute consumer_name.



12
13
14
# File 'lib/pact_broker/matrix/integration.rb', line 12

def consumer_name
  @consumer_name
end

#provider_idObject (readonly)

Returns the value of attribute provider_id.



12
13
14
# File 'lib/pact_broker/matrix/integration.rb', line 12

def provider_id
  @provider_id
end

#provider_nameObject (readonly)

Returns the value of attribute provider_name.



12
13
14
# File 'lib/pact_broker/matrix/integration.rb', line 12

def provider_name
  @provider_name
end

Class Method Details

.from_hash(hash) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/pact_broker/matrix/integration.rb', line 22

def self.from_hash hash
  new(
    hash.fetch(:consumer_id),
    hash.fetch(:consumer_name),
    hash.fetch(:provider_id),
    hash.fetch(:provider_name),
    hash.fetch(:required)
  )
end

Instance Method Details

#<=>(other) ⇒ Object



48
49
50
51
52
# File 'lib/pact_broker/matrix/integration.rb', line 48

def <=> other
  comparison = consumer_name <=> other.consumer_name
  return comparison if comparison != 0
  comparison =provider_name <=> other.provider_name
end

#==(other) ⇒ Object



44
45
46
# File 'lib/pact_broker/matrix/integration.rb', line 44

def == other
  consumer_id == other.consumer_id && provider_id == other.provider_id
end

#consumerObject



32
33
34
# File 'lib/pact_broker/matrix/integration.rb', line 32

def consumer
  @consumer ||= OpenStruct.new(name: consumer_name, id: consumer_id)
end

#involves_consumer_with_id?(consumer_id) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/pact_broker/matrix/integration.rb', line 71

def involves_consumer_with_id?(consumer_id)
  self.consumer_id == consumer_id
end

#involves_consumer_with_name?(consumer_name) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/pact_broker/matrix/integration.rb', line 83

def involves_consumer_with_name?(consumer_name)
  self.consumer_name == consumer_name
end

#involves_consumer_with_names?(consumer_names) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/pact_broker/matrix/integration.rb', line 75

def involves_consumer_with_names?(consumer_names)
  consumer_names.include?(self.consumer_name)
end

#involves_pacticipant_with_name?(pacticipant_name) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/pact_broker/matrix/integration.rb', line 91

def involves_pacticipant_with_name?(pacticipant_name)
  pacticipant_names.include?(pacticipant_name)
end

#involves_provider_with_name?(provider_name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/pact_broker/matrix/integration.rb', line 79

def involves_provider_with_name?(provider_name)
  self.provider_name == provider_name
end

#pacticipant_namesObject



63
64
65
# File 'lib/pact_broker/matrix/integration.rb', line 63

def pacticipant_names
  [consumer_name, provider_name]
end

#providerObject



36
37
38
# File 'lib/pact_broker/matrix/integration.rb', line 36

def provider
  @provider ||= OpenStruct.new(name: provider_name, id: provider_id)
end

#required?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pact_broker/matrix/integration.rb', line 40

def required?
  @required
end

#to_hashObject



54
55
56
57
58
59
60
61
# File 'lib/pact_broker/matrix/integration.rb', line 54

def to_hash
  {
    consumer_name: consumer_name,
    consumer_id: consumer_id,
    provider_name: provider_name,
    provider_id: provider_id,
  }
end

#to_sObject



67
68
69
# File 'lib/pact_broker/matrix/integration.rb', line 67

def to_s
  "Integration between #{consumer_name} (id=#{consumer_id}) and #{provider_name} (id=#{provider_id})"
end