Module: PactBroker::Matrix::MatrixRowInstanceMethods

Included in:
EveryRow, MatrixRow
Defined in:
lib/pact_broker/matrix/matrix_row_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 30

def <=> other
  comparisons = [
    compare_name_asc(consumer_name, other.consumer_name),
    compare_number_desc(consumer_version_order, other.consumer_version_order),
    compare_number_desc(pact_revision_number, other.pact_revision_number),
    compare_name_asc(provider_name, other.provider_name),
    compare_number_desc(provider_version_order, other.provider_version_order),
    compare_number_desc(verification_id, other.verification_id)
  ]

  comparisons.find{|c| c != 0 } || 0
end

#compare_name_asc(name1, name2) ⇒ Object



43
44
45
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 43

def compare_name_asc name1, name2
  name1 <=> name2
end

#compare_number_desc(number1, number2) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 51

def compare_number_desc number1, number2
  if number1 && number2
    number2 <=> number1
  elsif number1
    1
  else
    -1
  end
end

#consumer_nameObject



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

def consumer_name
  consumer.name
end

#consumer_version_branch_versionsObject



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

def consumer_version_branch_versions
  consumer_version.branch_versions
end

#consumer_version_deployed_versionsObject



95
96
97
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 95

def consumer_version_deployed_versions
  consumer_version.current_deployed_versions
end

#consumer_version_numberObject



87
88
89
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 87

def consumer_version_number
  consumer_version.number
end

#consumer_version_orderObject



103
104
105
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 103

def consumer_version_order
  consumer_version.order
end

#consumer_version_released_versionsObject



99
100
101
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 99

def consumer_version_released_versions
  consumer_version.current_supported_released_versions
end

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 61

def eql?(obj)
  (obj.class == model) && (obj.values == values)
end

#has_verification?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 135

def has_verification?
  !!verification_id
end

#involves_pacticipant_with_name?(pacticipant_name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 69

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

#last_action_dateObject



131
132
133
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 131

def last_action_date
  return_or_raise_if_not_set(:last_action_date)
end

#pact_created_atObject



21
22
23
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 21

def pact_created_at
  pact_publication.created_at
end

#pact_revision_numberObject



9
10
11
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 9

def pact_revision_number
  pact_publication.revision_number
end

#pact_version_shaObject



5
6
7
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 5

def pact_version_sha
  pact_version.sha
end

#pacticipant_namesObject



65
66
67
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 65

def pacticipant_names
  [consumer_name, provider_name]
end

#provider_nameObject



107
108
109
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 107

def provider_name
  provider.name
end

#provider_version_branch_versionsObject



115
116
117
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 115

def provider_version_branch_versions
  provider_version&.branch_versions || []
end

#provider_version_deployed_versionsObject



119
120
121
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 119

def provider_version_deployed_versions
  provider_version&.current_deployed_versions || []
end

#provider_version_idObject



73
74
75
76
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 73

def provider_version_id
  # null when not verified
  values[:provider_version_id]
end

#provider_version_numberObject



111
112
113
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 111

def provider_version_number
  provider_version&.number
end

#provider_version_orderObject



127
128
129
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 127

def provider_version_order
  provider_version&.order
end

#provider_version_released_versionsObject



123
124
125
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 123

def provider_version_released_versions
  provider_version&.current_supported_released_versions || []
end

#return_or_raise_if_not_set(key) ⇒ Object

This model needs the verifications and pacticipants joined to it before it can be used, as it’s not a “real” model.



141
142
143
144
145
146
147
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 141

def return_or_raise_if_not_set(key)
  if values.key?(key)
    values[key]
  else
    raise "Required table not joined"
  end
end

#successObject



17
18
19
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 17

def success
  verification&.success
end

#to_sObject



47
48
49
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 47

def to_s
  "#{consumer_name} v#{consumer_version_number} #{provider_name} #{provider_version_number} #{success}"
end

#verification_executed_atObject



25
26
27
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 25

def verification_executed_at
  verification&.execution_date
end

#verification_idObject



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

def verification_id
  # null when not verified
  return_or_raise_if_not_set(:verification_id)
end

#verification_numberObject



13
14
15
# File 'lib/pact_broker/matrix/matrix_row_instance_methods.rb', line 13

def verification_number
  verification&.number
end