Class: PactBroker::Matrix::ResolvedSelector

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

Constant Summary collapse

NULL_VERSION_ID =

A version ID of -1 will not match any rows, which is what we want to ensure that no matrix rows are returned for a version that does not exist.

-1
NULL_PACTICIPANT_ID =
-1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ResolvedSelector

Returns a new instance of ResolvedSelector.



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

def initialize(params = {})
  merge!(params)
end

Class Method Details

.for_non_existing_pacticipant(original_selector, type, ignore) ⇒ Object

This is not possible for specified selectors, as there is validation at the HTTP query level to ensure that all pacticipants in the specified selectors exist. It is possible for the ignore selectors however.



38
39
40
41
42
43
44
45
46
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 38

def self.for_non_existing_pacticipant(original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: NULL_PACTICIPANT_ID,
    pacticipant_name: original_selector[:pacticipant_name],
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end

.for_pacticipant(pacticipant, original_selector, type, ignore) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 25

def self.for_pacticipant(pacticipant, original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end

.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) ⇒ Object

rubocop: enable Metrics/ParameterLists



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 68

def self.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    pacticipant_version_id: NULL_VERSION_ID,
    pacticipant_version_number: original_selector[:pacticipant_version_number],
    latest: original_selector[:latest],
    tag: original_selector[:tag],
    branch: original_selector[:branch],
    main_branch: original_selector[:main_branch],
    environment_name: original_selector[:environment_name],
    type: type,
    ignore: ignore,
    original_selector: original_selector
  )
end

.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) ⇒ Object

rubocop: disable Metrics/ParameterLists



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 49

def self.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    pacticipant_version_id: version.id,
    pacticipant_version_number: version.number,
    latest: original_selector[:latest],
    tag: original_selector[:tag],
    branch: original_selector[:branch] || (original_selector[:main_branch] ? version&.values[:branch_name] : nil),
    main_branch: original_selector[:main_branch],
    environment_name: original_selector[:environment_name],
    type: type,
    ignore: ignore,
    one_of_many: one_of_many,
    original_selector: original_selector
  )
end

Instance Method Details

#branchString

Returns the name of the branch.

Returns:

  • (String)

    the name of the branch



114
115
116
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 114

def branch
  self[:branch]
end

#consider?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 190

def consider?
  !ignore?
end

#descriptionObject

rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 199

def description
  if latest_tagged? && pacticipant_version_number
    "the latest version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})"
  elsif latest_tagged?
    "the latest version of #{pacticipant_name} with tag #{tag} (no such version exists)"
  elsif latest_from_main_branch? && pacticipant_version_number.nil?
    "the latest version of #{pacticipant_name} from the main branch (no versions exist for this branch)"
  elsif main_branch? && pacticipant_version_number.nil?
    "any version of #{pacticipant_name} from the main branch (no versions exist for this branch)"
  elsif latest_from_branch? && pacticipant_version_number
    "the latest version of #{pacticipant_name} from branch #{branch} (#{pacticipant_version_number})"
  elsif latest_from_branch?
    "the latest version of #{pacticipant_name} from branch #{branch} (no such version exists)"
  elsif branch && pacticipant_version_number
    prefix = one_of_many? ? "one of the versions " : "the version "
    prefix + "of #{pacticipant_name} from branch #{branch} (#{pacticipant_version_number})"
  elsif branch
    "a version of #{pacticipant_name} from branch #{branch} (no such version exists)"
  elsif latest? && pacticipant_version_number
    "the latest version of #{pacticipant_name} (#{pacticipant_version_number})"
  elsif latest?
    "the latest version of #{pacticipant_name} (no such version exists)"
  elsif tag && pacticipant_version_number
    "a version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})"
  elsif tag
    "a version of #{pacticipant_name} with tag #{tag} (no such version exists)"
  elsif environment_name && pacticipant_version_number
    prefix = one_of_many? ? "one of the versions" : "the version"
    "#{prefix} of #{pacticipant_name} currently in #{environment_name} (#{pacticipant_version_number})"
  elsif environment_name
    "a version of #{pacticipant_name} currently in #{environment_name} (no version is currently recorded as deployed/released in this environment)"
  elsif pacticipant_version_number && version_does_not_exist?
    "version #{pacticipant_version_number} of #{pacticipant_name} (no such version exists)"
  elsif pacticipant_version_number
    "version #{pacticipant_version_number} of #{pacticipant_name}"
  elsif pacticipant_does_not_exist?
    "any version of #{pacticipant_name} (no such pacticipant exists)"
  else
    "any version of #{pacticipant_name}"
  end
end

#environment_nameObject



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

def environment_name
  self[:environment_name]
end

#ignore?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 186

def ignore?
  self[:ignore]
end

#inferred?Boolean

Was this selector inferred based on the user’s query? (ie. the integrations were calculated because only one selector was specified)

Returns:

  • (Boolean)


178
179
180
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 178

def inferred?
  self[:type] == :inferred
end

#latest?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 105

def latest?
  self[:latest]
end

#latest_from_branch?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 143

def latest_from_branch?
  latest? && branch
end

#latest_from_main_branch?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 147

def latest_from_main_branch?
  latest? && main_branch?
end

#latest_tagged?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 139

def latest_tagged?
  latest? && tag
end

#main_branch?Boolean

Returns:

  • (Boolean)


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

def main_branch?
  self[:main_branch]
end

#most_specific_criterionObject



127
128
129
130
131
132
133
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 127

def most_specific_criterion
  if pacticipant_version_id
    { pacticipant_version_id: pacticipant_version_id }
  else
    { pacticipant_id: pacticipant_id }
  end
end

#one_of_many?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 182

def one_of_many?
  self[:one_of_many]
end

#only_pacticipant_name_specified?Boolean

Returns:

  • (Boolean)


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

def only_pacticipant_name_specified?
  !!pacticipant_name && self[:original_selector].without(:pacticipant_name).none?{ |_key, value| value }
end

#original_selectorObject



194
195
196
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 194

def original_selector
  self[:original_selector]
end

#pacticipant_does_not_exist?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 155

def pacticipant_does_not_exist?
  self[:pacticipant_id] == NULL_PACTICIPANT_ID
end

#pacticipant_idObject



89
90
91
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 89

def pacticipant_id
  self[:pacticipant_id]
end

#pacticipant_nameObject



93
94
95
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 93

def pacticipant_name
  self[:pacticipant_name]
end

#pacticipant_or_version_does_not_exist?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 151

def pacticipant_or_version_does_not_exist?
  pacticipant_does_not_exist? || version_does_not_exist?
end

#pacticipant_version_idObject



97
98
99
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 97

def pacticipant_version_id
  self[:pacticipant_version_id]
end

#pacticipant_version_numberObject



101
102
103
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 101

def pacticipant_version_number
  self[:pacticipant_version_number]
end

#pacticipant_version_specified_in_original_selector?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 85

def pacticipant_version_specified_in_original_selector?
  !!self.dig(:original_selector, :pacticipant_version_number)
end

#specified?Boolean

Did the user specify this selector in the user’s query?

Returns:

  • (Boolean)


172
173
174
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 172

def specified?
  self[:type] == :specified
end

#specified_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 163

def specified_version_that_does_not_exist?
  specified? && version_does_not_exist?
end

#tagObject



109
110
111
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 109

def tag
  self[:tag]
end

#version_does_not_exist?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 159

def version_does_not_exist?
  !version_exists?
end

#version_does_not_exist_descriptionObject

rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 242

def version_does_not_exist_description
  if version_does_not_exist?
    if tag
      "No version with tag #{tag} exists for #{pacticipant_name}"
    elsif branch
      "No version of #{pacticipant_name} from branch #{branch} exists"
    elsif main_branch?
      "No version of #{pacticipant_name} from the main branch exists"
    elsif environment_name
      "No version of #{pacticipant_name} is currently recorded as deployed or released in environment #{environment_name}"
    elsif pacticipant_version_number
      "No pacts or verifications have been published for version #{pacticipant_version_number} of #{pacticipant_name}"
    else
      "No pacts or verifications have been published for #{pacticipant_name}"
    end
  else
    ""
  end
end

#version_exists?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 167

def version_exists?
  pacticipant_version_id != NULL_VERSION_ID
end