Class: PactBroker::Domain::IndexItem

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

Instance Method Summary collapse

Constructor Details

#initialize(consumer, provider, consumer_version = nil, 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



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

def initialize(consumer, provider, consumer_version = nil, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
  @consumer = consumer
  @provider = provider
  @consumer_version = consumer_version
  @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 Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



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

def <=> other
  comparisons = [
    compare_name_asc(consumer_name, other.consumer_name),
    compare_number_desc(consumer_version.order, other.consumer_version.order),
    compare_number_desc(latest_pact.revision_number, other.latest_pact.revision_number),
    compare_name_asc(provider_name, other.provider_name)
  ]

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

#==(other) ⇒ Object

rubocop: enable Metrics/CyclomaticComplexity



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

def == other
  eq?(other)
end

#any_webhooks?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/pact_broker/domain/index_item.rb', line 121

def any_webhooks?
  @webhooks.any?
end

#compare_name_asc(name1, name2) ⇒ Object



177
178
179
# File 'lib/pact_broker/domain/index_item.rb', line 177

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

#compare_number_desc(number1, number2) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/pact_broker/domain/index_item.rb', line 181

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

#connected?(other) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/pact_broker/domain/index_item.rb', line 157

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

#consumer_nameObject



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

def consumer_name
  consumer.name
end

#consumer_version_branch_headsObject



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

def consumer_version_branch_heads
  consumer_version.branch_heads
end

#consumer_version_branchesObject



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

def consumer_version_branches
  consumer_version.branch_heads.collect(&:branch_name)
end

#consumer_version_environment_namesObject



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

def consumer_version_environment_names
  (consumer_version.current_deployed_versions.collect(&:environment).collect(&:name) + consumer_version.current_supported_released_versions.collect(&:environment).collect(&:name)).uniq
end

#consumer_version_numberObject



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

def consumer_version_number
  @latest_pact.consumer_version_number
end

#consumer_version_orderObject



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

def consumer_version_order
  consumer_version.order
end

#eq?(other) ⇒ Boolean

rubocop: disable Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/pact_broker/domain/index_item.rb', line 39

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)


137
138
139
# File 'lib/pact_broker/domain/index_item.rb', line 137

def ever_verified?
  !!latest_verification
end

#include?(pacticipant) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#last_activity_dateObject



199
200
201
# File 'lib/pact_broker/domain/index_item.rb', line 199

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



129
130
131
# File 'lib/pact_broker/domain/index_item.rb', line 129

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)


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

def latest?
  @latest
end

#latest_for_branch?Boolean

Returns:

  • (Boolean)


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

def latest_for_branch?
  @latest_for_branch
end

#latest_verification_provider_version_numberObject



149
150
151
# File 'lib/pact_broker/domain/index_item.rb', line 149

def latest_verification_provider_version_number
  latest_verification.provider_version.number
end

#latest_verification_successful?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/pact_broker/domain/index_item.rb', line 141

def latest_verification_successful?
  latest_verification.success
end

#pact_changed_since_last_verification?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/pact_broker/domain/index_item.rb', line 145

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

#pacticipantsObject



153
154
155
# File 'lib/pact_broker/domain/index_item.rb', line 153

def pacticipants
  [consumer, provider]
end

#provider_nameObject



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

def provider_name
  provider.name
end

#provider_versionObject



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

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

#provider_version_branch_headsObject



97
98
99
# File 'lib/pact_broker/domain/index_item.rb', line 97

def provider_version_branch_heads
  provider_version&.branch_heads || []
end

#provider_version_branchesObject



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

def provider_version_branches
  provider_version&.branch_heads&.collect(&:branch_name) || []
end

#provider_version_environment_namesObject



106
107
108
109
110
111
112
113
# File 'lib/pact_broker/domain/index_item.rb', line 106

def provider_version_environment_names
  if provider_version
    (provider_deployed_environment_names + provider_released_environment_names).uniq
  else
    []
  end

end

#provider_version_numberObject



93
94
95
# File 'lib/pact_broker/domain/index_item.rb', line 93

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

#pseudo_branch_verification_statusObject



133
134
135
# File 'lib/pact_broker/domain/index_item.rb', line 133

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



117
118
119
# File 'lib/pact_broker/domain/index_item.rb', line 117

def tag_names
  @tags
end

#to_aObject



195
196
197
# File 'lib/pact_broker/domain/index_item.rb', line 195

def to_a
  [consumer, provider]
end

#to_sObject



191
192
193
# File 'lib/pact_broker/domain/index_item.rb', line 191

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

#webhook_statusObject



125
126
127
# File 'lib/pact_broker/domain/index_item.rb', line 125

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