Class: PactBroker::Matrix::QuickRow

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

Direct Known Subclasses

EveryRow

Constant Summary collapse

LV =

Tables

:latest_verification_id_for_pact_version_and_provider_version
LP =
:latest_pact_publication_ids_for_consumer_versions
LP_LV_JOIN =

Joins

{ Sequel[:p][:pact_version_id] => Sequel[:v][:pact_version_id] }
CONSUMER_VERSION_JOIN =
{ Sequel[:p][:consumer_version_id] => Sequel[:cv][:id] }
PROVIDER_VERSION_JOIN =
{ Sequel[:v][:provider_version_id] => Sequel[:pv][:id] }
PACT_COLUMNS =
[
  Sequel[:p][:consumer_id],
  Sequel[:p][:provider_id],
  Sequel[:p][:consumer_version_id],
  Sequel[:p][:pact_publication_id],
  Sequel[:p][:pact_version_id],
  Sequel[:p][:created_at].as(:consumer_version_created_at),
  Sequel[:p][:pact_publication_id].as(:pact_order)
]
VERIFICATION_COLUMNS =
[
  Sequel[:v][:provider_version_id],
  Sequel[:v][:verification_id],
  Sequel[:v][:created_at].as(:provider_version_created_at)
]
LAST_ACTION_DATE =
Sequel.lit("CASE WHEN (provider_version_created_at IS NOT NULL AND provider_version_created_at > consumer_version_created_at) THEN provider_version_created_at ELSE consumer_version_created_at END").as(:last_action_date)
ALL_COLUMNS =
PACT_COLUMNS + VERIFICATION_COLUMNS
SELECT_ALL_COLUMN_ARGS =

cachable select arguments

[:select_all_columns] + ALL_COLUMNS
SELECT_PACTICIPANT_IDS_ARGS =
[:select_pacticipant_ids, Sequel[:p][:consumer_id], Sequel[:p][:provider_id]]

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/pact_broker/matrix/quick_row.rb', line 293

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



306
307
308
# File 'lib/pact_broker/matrix/quick_row.rb', line 306

def compare_name_asc name1, name2
  name1 <=> name2
end

#compare_number_desc(number1, number2) ⇒ Object



314
315
316
317
318
319
320
321
322
# File 'lib/pact_broker/matrix/quick_row.rb', line 314

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

#consumer_nameObject



346
347
348
# File 'lib/pact_broker/matrix/quick_row.rb', line 346

def consumer_name
  consumer.name
end

#consumer_version_numberObject



350
351
352
# File 'lib/pact_broker/matrix/quick_row.rb', line 350

def consumer_version_number
  consumer_version.number
end

#consumer_version_orderObject



354
355
356
# File 'lib/pact_broker/matrix/quick_row.rb', line 354

def consumer_version_order
  consumer_version.order
end

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


324
325
326
# File 'lib/pact_broker/matrix/quick_row.rb', line 324

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

#has_verification?Boolean

Returns:

  • (Boolean)


374
375
376
# File 'lib/pact_broker/matrix/quick_row.rb', line 374

def has_verification?
  !!verification_id
end

#involves_pacticipant_with_name?(pacticipant_name) ⇒ Boolean

Returns:

  • (Boolean)


332
333
334
# File 'lib/pact_broker/matrix/quick_row.rb', line 332

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

#last_action_dateObject



370
371
372
# File 'lib/pact_broker/matrix/quick_row.rb', line 370

def last_action_date
  return_or_raise_if_not_set(:last_action_date)
end

#pact_created_atObject



284
285
286
# File 'lib/pact_broker/matrix/quick_row.rb', line 284

def pact_created_at
  pact_publication.created_at
end

#pact_revision_numberObject



272
273
274
# File 'lib/pact_broker/matrix/quick_row.rb', line 272

def pact_revision_number
  pact_publication.revision_number
end

#pact_version_shaObject



268
269
270
# File 'lib/pact_broker/matrix/quick_row.rb', line 268

def pact_version_sha
  pact_version.sha
end

#pacticipant_namesObject



328
329
330
# File 'lib/pact_broker/matrix/quick_row.rb', line 328

def pacticipant_names
  [consumer_name, provider_name]
end

#provider_nameObject



358
359
360
# File 'lib/pact_broker/matrix/quick_row.rb', line 358

def provider_name
  provider.name
end

#provider_version_idObject



336
337
338
339
# File 'lib/pact_broker/matrix/quick_row.rb', line 336

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

#provider_version_numberObject



362
363
364
# File 'lib/pact_broker/matrix/quick_row.rb', line 362

def provider_version_number
  provider_version&.number
end

#provider_version_orderObject



366
367
368
# File 'lib/pact_broker/matrix/quick_row.rb', line 366

def provider_version_order
  provider_version&.order
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.



380
381
382
383
384
385
386
# File 'lib/pact_broker/matrix/quick_row.rb', line 380

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

#successObject

end dataset_module



264
265
266
# File 'lib/pact_broker/matrix/quick_row.rb', line 264

def success
  verification&.success
end

#to_sObject



310
311
312
# File 'lib/pact_broker/matrix/quick_row.rb', line 310

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

#verification_executed_atObject



288
289
290
# File 'lib/pact_broker/matrix/quick_row.rb', line 288

def verification_executed_at
  verification&.execution_date
end

#verification_idObject



341
342
343
344
# File 'lib/pact_broker/matrix/quick_row.rb', line 341

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

#verification_numberObject



276
277
278
# File 'lib/pact_broker/matrix/quick_row.rb', line 276

def verification_number
  verification&.number
end