Class: PactBroker::Matrix::Row

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

Direct Known Subclasses

HeadRow, LatestRow

Constant Summary collapse

TP_COLS =

Used when using table_print to output query results

[ :consumer_version_number, :pact_revision_number, :provider_version_number, :verification_number]

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/pact_broker/matrix/row.rb', line 179

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

#[](key) ⇒ Object

Temporary method while we transition from returning Hashes to return Matrix objects from the repository find methods Need to make the object act as a hash and an object



106
107
108
109
110
111
112
# File 'lib/pact_broker/matrix/row.rb', line 106

def [] key
  if key == :provider_version_tags || key == :consumer_version_tags
    send(key)
  else
    super
  end
end

#compare_name_asc(name1, name2) ⇒ Object



193
194
195
# File 'lib/pact_broker/matrix/row.rb', line 193

def compare_name_asc name1, name2
  name1 <=> name2
end

#compare_number_desc(number1, number2) ⇒ Object



201
202
203
204
205
206
207
208
209
# File 'lib/pact_broker/matrix/row.rb', line 201

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

#consumerObject



132
133
134
# File 'lib/pact_broker/matrix/row.rb', line 132

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

#consumer_head_tag_namesObject

tags for which this pact publication is the latest of that tag this is set in the code rather than the database



116
117
118
# File 'lib/pact_broker/matrix/row.rb', line 116

def consumer_head_tag_names
  @consumer_head_tag_names ||= []
end

#consumer_head_tag_names=(consumer_head_tag_names) ⇒ Object



120
121
122
# File 'lib/pact_broker/matrix/row.rb', line 120

def consumer_head_tag_names= consumer_head_tag_names
  @consumer_head_tag_names = consumer_head_tag_names
end

#consumer_versionObject



140
141
142
# File 'lib/pact_broker/matrix/row.rb', line 140

def consumer_version
  @consumer_version ||= OpenStruct.new(number: consumer_version_number, id: consumer_version_id, pacticipant: consumer)
end

#eql?(obj) ⇒ Boolean

Need to overwrite eql? from lib/sequel/model/base.rb because it uses @values instead of self.values so the success boolean/integer problem mentioned above screws things up

Returns:

  • (Boolean)


229
230
231
# File 'lib/pact_broker/matrix/row.rb', line 229

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

#latest_verificationObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/pact_broker/matrix/row.rb', line 161

def latest_verification
  if verification_executed_at
    @latest_verification ||= OpenStruct.new(
      id: verification_id,
      success: success,
      number: verification_number,
      execution_date: verification_executed_at,
      created_at: verification_executed_at,
      provider_version_number: provider_version_number,
      build_url: verification_build_url,
      provider_version: provider_version,
      consumer_name: consumer_name,
      provider_name: provider_name
    )
  end
end

#pactObject



150
151
152
153
154
155
156
157
158
159
# File 'lib/pact_broker/matrix/row.rb', line 150

def pact
  @pact ||= OpenStruct.new(consumer: consumer,
    provider: provider,
    consumer_version: consumer_version,
    consumer_version_number: consumer_version_number,
    created_at: pact_created_at,
    revision_number: pact_revision_number,
    pact_version_sha: pact_version_sha
  )
end

#providerObject



136
137
138
# File 'lib/pact_broker/matrix/row.rb', line 136

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

#provider_versionObject



144
145
146
147
148
# File 'lib/pact_broker/matrix/row.rb', line 144

def provider_version
  if provider_version_number
    @provider_version ||= OpenStruct.new(number: provider_version_number, id: provider_version_id, pacticipant: provider)
  end
end

#successObject

For some reason, with MySQL, the success column value comes back as an integer rather than a boolean for the latest_matrix view (but not the matrix view!) Maybe something to do with the union? Haven’t investigated as this is an easy enough fix.



216
217
218
219
# File 'lib/pact_broker/matrix/row.rb', line 216

def success
  value = super
  value.nil? ? nil : value == true || value == 1
end

#summaryObject

def latest_triggered_webhooks

@latest_triggered_webhooks ||= []

end



128
129
130
# File 'lib/pact_broker/matrix/row.rb', line 128

def summary
  "#{consumer_name}#{consumer_version_number} #{provider_name}#{provider_version_number || '?'} (r#{pact_revision_number}n#{verification_number || '?'})"
end

#to_sObject



197
198
199
# File 'lib/pact_broker/matrix/row.rb', line 197

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

#valuesObject



221
222
223
# File 'lib/pact_broker/matrix/row.rb', line 221

def values
  super.merge(success: success)
end