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.



15
16
17
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 15

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

Class Method Details

.for_non_existing_pacticipant(original_selector, type, ignore) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 29

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



19
20
21
22
23
24
25
26
27
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 19

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 59

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 40

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



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

def branch
  self[:branch]
end

#consider?Boolean

Returns:

  • (Boolean)


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

def consider?
  !ignore?
end

#descriptionObject

rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength



186
187
188
189
190
191
192
193
194
195
196
197
198
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
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 186

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 main_branch? && pacticipant_version_number.nil?
    "a version of #{pacticipant_name} from the main branch (no such version exists)"
  elsif latest_from_main_branch? && pacticipant_version_number.nil?
    "the latest version of #{pacticipant_name} from the main branch (no such verison exists)"
  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 deployed or released to #{environment_name} (#{pacticipant_version_number})"
  elsif environment_name
    "a version of #{pacticipant_name} currently deployed or released to #{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



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

def environment_name
  self[:environment_name]
end

#ignore?Boolean

Returns:

  • (Boolean)


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

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)


169
170
171
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 169

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

#latest?Boolean

Returns:

  • (Boolean)


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

def latest?
  self[:latest]
end

#latest_from_branch?Boolean

Returns:

  • (Boolean)


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

def latest_from_branch?
  latest? && branch
end

#latest_from_main_branch?Boolean

Returns:

  • (Boolean)


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

def latest_from_main_branch?
  latest? && main_branch?
end

#latest_tagged?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 130

def latest_tagged?
  latest? && tag
end

#main_branch?Boolean

Returns:

  • (Boolean)


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

def main_branch?
  self[:main_branch]
end

#most_specific_criterionObject



118
119
120
121
122
123
124
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 118

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)


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

def one_of_many?
  self[:one_of_many]
end

#only_pacticipant_name_specified?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 126

def only_pacticipant_name_specified?
  !!pacticipant_name && !branch && !tag && !latest? && !pacticipant_version_number && !main_branch?
end

#pacticipant_does_not_exist?Boolean

Returns:

  • (Boolean)


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

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

#pacticipant_idObject



80
81
82
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 80

def pacticipant_id
  self[:pacticipant_id]
end

#pacticipant_nameObject



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

def pacticipant_name
  self[:pacticipant_name]
end

#pacticipant_or_version_does_not_exist?Boolean

Returns:

  • (Boolean)


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

def pacticipant_or_version_does_not_exist?
  pacticipant_does_not_exist? || version_does_not_exist?
end

#pacticipant_version_idObject



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

def pacticipant_version_id
  self[:pacticipant_version_id]
end

#pacticipant_version_numberObject



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

def pacticipant_version_number
  self[:pacticipant_version_number]
end

#pacticipant_version_specified_in_original_selector?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 76

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)


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

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

#specified_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


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

def specified_version_that_does_not_exist?
  specified? && version_does_not_exist?
end

#tagObject



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

def tag
  self[:tag]
end

#version_does_not_exist?Boolean

Returns:

  • (Boolean)


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

def version_does_not_exist?
  !version_exists?
end

#version_does_not_exist_descriptionObject

rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 229

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)


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

def version_exists?
  pacticipant_version_id != NULL_VERSION_ID
end