Class: PactBroker::Domain::IndexItem

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil) ⇒ IndexItem

rubocop:disable Metrics/ParameterLists



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pact_broker/domain/index_item.rb', line 22

def initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
  @consumer = consumer
  @provider = provider
  @latest_pact = latest_pact
  @latest = latest
  @latest_verification = latest_verification
  @webhooks = webhooks
  @triggered_webhooks = triggered_webhooks
  @tags = tags
  @latest_verification_latest_tags = latest_verification_latest_tags
  @latest_for_branch = latest_for_branch
end

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def consumer
  @consumer
end

#latest_pactObject (readonly)

Returns the value of attribute latest_pact.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_pact
  @latest_pact
end

#latest_verificationObject (readonly)

Returns the value of attribute latest_verification.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_verification
  @latest_verification
end

#latest_verification_latest_tagsObject (readonly)

Returns the value of attribute latest_verification_latest_tags.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_verification_latest_tags
  @latest_verification_latest_tags
end

#providerObject (readonly)

Returns the value of attribute provider.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def provider
  @provider
end

#triggered_webhooksObject (readonly)

Returns the value of attribute triggered_webhooks.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def triggered_webhooks
  @triggered_webhooks
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def webhooks
  @webhooks
end

Class Method Details

.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



16
17
18
# File 'lib/pact_broker/domain/index_item.rb', line 16

def self.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
  new(consumer, provider, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags, latest_for_branch)
end

Instance Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



150
151
152
153
154
# File 'lib/pact_broker/domain/index_item.rb', line 150

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

#==(other) ⇒ Object



45
46
47
# File 'lib/pact_broker/domain/index_item.rb', line 45

def == other
  eq?(other)
end

#any_webhooks?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/pact_broker/domain/index_item.rb', line 99

def any_webhooks?
  @webhooks.any?
end

#compare_name_asc(name1, name2) ⇒ Object



161
162
163
# File 'lib/pact_broker/domain/index_item.rb', line 161

def compare_name_asc name1, name2
  name1&.downcase <=> name2&.downcase
end

#compare_number_desc(number1, number2) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/pact_broker/domain/index_item.rb', line 165

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

#connected?(other) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/pact_broker/domain/index_item.rb', line 135

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

#consumer_nameObject



49
50
51
# File 'lib/pact_broker/domain/index_item.rb', line 49

def consumer_name
  consumer.name
end

#consumer_versionObject



69
70
71
# File 'lib/pact_broker/domain/index_item.rb', line 69

def consumer_version
  @latest_pact.consumer_version
end

#consumer_version_branchObject



73
74
75
# File 'lib/pact_broker/domain/index_item.rb', line 73

def consumer_version_branch
  consumer_version.branch
end

#consumer_version_numberObject



61
62
63
# File 'lib/pact_broker/domain/index_item.rb', line 61

def consumer_version_number
  @latest_pact.consumer_version_number
end

#consumer_version_orderObject



65
66
67
# File 'lib/pact_broker/domain/index_item.rb', line 65

def consumer_version_order
  consumer_version.order
end

#eq?(other) ⇒ Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/pact_broker/domain/index_item.rb', line 36

def eq? other
  IndexItem === other && other.consumer == consumer && other.provider == provider &&
    other.latest_pact == latest_pact &&
    other.latest? == latest? &&
    other.latest_verification == latest_verification &&
    other.webhooks == webhooks &&
    other.latest_for_branch? == latest_for_branch?
end

#ever_verified?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/pact_broker/domain/index_item.rb', line 115

def ever_verified?
  !!latest_verification
end

#include?(pacticipant) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/pact_broker/domain/index_item.rb', line 139

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

#last_activity_dateObject



183
184
185
# File 'lib/pact_broker/domain/index_item.rb', line 183

def last_activity_date
  @last_activity_date ||= [latest_pact.created_at, latest_verification ? latest_verification.execution_date : nil].compact.max
end

#last_webhook_execution_dateObject



107
108
109
# File 'lib/pact_broker/domain/index_item.rb', line 107

def last_webhook_execution_date
  @last_webhook_execution_date ||= @triggered_webhooks.any? ? @triggered_webhooks.sort{|a, b| a.created_at <=> b.created_at }.last.created_at : nil
end

#latest?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/pact_broker/domain/index_item.rb', line 57

def latest?
  @latest
end

#latest_for_branch?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/pact_broker/domain/index_item.rb', line 77

def latest_for_branch?
  @latest_for_branch
end

#latest_verification_provider_version_numberObject



127
128
129
# File 'lib/pact_broker/domain/index_item.rb', line 127

def latest_verification_provider_version_number
  latest_verification.provider_version.number
end

#latest_verification_successful?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/pact_broker/domain/index_item.rb', line 119

def latest_verification_successful?
  latest_verification.success
end

#pact_changed_since_last_verification?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/pact_broker/domain/index_item.rb', line 123

def pact_changed_since_last_verification?
  latest_verification.pact_version_sha != latest_pact.pact_version_sha
end

#pacticipantsObject



131
132
133
# File 'lib/pact_broker/domain/index_item.rb', line 131

def pacticipants
  [consumer, provider]
end

#provider_nameObject



53
54
55
# File 'lib/pact_broker/domain/index_item.rb', line 53

def provider_name
  provider.name
end

#provider_versionObject



81
82
83
# File 'lib/pact_broker/domain/index_item.rb', line 81

def provider_version
  @latest_verification ? @latest_verification.provider_version : nil
end

#provider_version_branchObject



89
90
91
# File 'lib/pact_broker/domain/index_item.rb', line 89

def provider_version_branch
  provider_version&.branch
end

#provider_version_numberObject



85
86
87
# File 'lib/pact_broker/domain/index_item.rb', line 85

def provider_version_number
  @latest_verification ? @latest_verification.provider_version_number : nil
end

#pseudo_branch_verification_statusObject



111
112
113
# File 'lib/pact_broker/domain/index_item.rb', line 111

def pseudo_branch_verification_status
  @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(@latest_pact, @latest_verification).to_sym
end

#tag_namesObject

these are the consumer tag names for which this pact publication is the latest with that tag



95
96
97
# File 'lib/pact_broker/domain/index_item.rb', line 95

def tag_names
  @tags
end

#to_aObject



179
180
181
# File 'lib/pact_broker/domain/index_item.rb', line 179

def to_a
  [consumer, provider]
end

#to_sObject



175
176
177
# File 'lib/pact_broker/domain/index_item.rb', line 175

def to_s
  "Pact between #{consumer_name} #{consumer_version_number} and #{provider_name} #{provider_version_number}"
end

#webhook_statusObject



103
104
105
# File 'lib/pact_broker/domain/index_item.rb', line 103

def webhook_status
  @webhook_status ||= PactBroker::Webhooks::Status.new(@latest_pact, @webhooks, @triggered_webhooks).to_sym
end