Class: PactBroker::Pacts::Selector
- Inherits:
-
Hash
- Object
- Hash
- PactBroker::Pacts::Selector
show all
- Defined in:
- lib/pact_broker/pacts/selector.rb
Overview
rubocop: disable Metrics/ClassLength
Constant Summary
collapse
- PROPERTY_NAMES =
[:latest, :tag, :branch, :consumer, :consumer_version, :environment_name, :fallback_tag, :fallback_branch, :main_branch, :matching_branch, :currently_supported, :currently_deployed]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(properties = {}) ⇒ Selector
Returns a new instance of Selector.
11
12
13
14
|
# File 'lib/pact_broker/pacts/selector.rb', line 11
def initialize(properties = {})
properties.without(*PROPERTY_NAMES).tap { |it| warn("WARN: Unsupported property for #{self.class.name}: #{it.keys.join(", ")} at #{caller[0..3]}") if it.any? }
merge!(properties)
end
|
Class Method Details
.all_for_tag(tag) ⇒ Object
164
165
166
|
# File 'lib/pact_broker/pacts/selector.rb', line 164
def self.all_for_tag(tag)
new(tag: tag)
end
|
.all_for_tag_and_consumer(tag, consumer) ⇒ Object
168
169
170
|
# File 'lib/pact_broker/pacts/selector.rb', line 168
def self.all_for_tag_and_consumer(tag, consumer)
new(tag: tag, consumer: consumer)
end
|
.for_currently_deployed(environment_name = nil) ⇒ Object
184
185
186
|
# File 'lib/pact_broker/pacts/selector.rb', line 184
def self.for_currently_deployed(environment_name = nil)
new( { currently_deployed: true, environment_name: environment_name }.compact )
end
|
.for_currently_deployed_and_consumer(consumer) ⇒ Object
192
193
194
|
# File 'lib/pact_broker/pacts/selector.rb', line 192
def self.for_currently_deployed_and_consumer(consumer)
new(currently_deployed: true, consumer: consumer)
end
|
.for_currently_deployed_and_environment_and_consumer(environment_name, consumer) ⇒ Object
196
197
198
|
# File 'lib/pact_broker/pacts/selector.rb', line 196
def self.for_currently_deployed_and_environment_and_consumer(environment_name, consumer)
new(currently_deployed: true, environment_name: environment_name, consumer: consumer)
end
|
.for_currently_supported(environment_name = nil) ⇒ Object
188
189
190
|
# File 'lib/pact_broker/pacts/selector.rb', line 188
def self.for_currently_supported(environment_name = nil)
new( { currently_supported: true, environment_name: environment_name }.compact )
end
|
.for_currently_supported_and_environment_and_consumer(environment_name, consumer) ⇒ Object
200
201
202
|
# File 'lib/pact_broker/pacts/selector.rb', line 200
def self.for_currently_supported_and_environment_and_consumer(environment_name, consumer)
new(currently_supported: true, environment_name: environment_name, consumer: consumer)
end
|
.for_environment(environment_name) ⇒ Object
204
205
206
|
# File 'lib/pact_broker/pacts/selector.rb', line 204
def self.for_environment(environment_name)
new(environment_name: environment_name)
end
|
.for_environment_and_consumer(environment_name, consumer) ⇒ Object
208
209
210
|
# File 'lib/pact_broker/pacts/selector.rb', line 208
def self.for_environment_and_consumer(environment_name, consumer)
new(environment_name: environment_name, consumer: consumer)
end
|
.for_main_branch ⇒ Object
144
145
146
|
# File 'lib/pact_broker/pacts/selector.rb', line 144
def self.for_main_branch
new(main_branch: true)
end
|
.from_hash(hash) ⇒ Object
212
213
214
|
# File 'lib/pact_broker/pacts/selector.rb', line 212
def self.from_hash hash
new(hash)
end
|
.latest_for_branch(branch) ⇒ Object
152
153
154
|
# File 'lib/pact_broker/pacts/selector.rb', line 152
def self.latest_for_branch(branch)
new(latest: true, branch: branch)
end
|
.latest_for_branch_and_consumer(branch, consumer) ⇒ Object
176
177
178
|
# File 'lib/pact_broker/pacts/selector.rb', line 176
def self.latest_for_branch_and_consumer(branch, consumer)
new(latest: true, branch: branch, consumer: consumer)
end
|
.latest_for_branch_with_fallback(branch, fallback_branch) ⇒ Object
160
161
162
|
# File 'lib/pact_broker/pacts/selector.rb', line 160
def self.latest_for_branch_with_fallback(branch, fallback_branch)
new(latest: true, branch: branch, fallback_branch: fallback_branch)
end
|
.latest_for_consumer(consumer) ⇒ Object
180
181
182
|
# File 'lib/pact_broker/pacts/selector.rb', line 180
def self.latest_for_consumer(consumer)
new(latest: true, consumer: consumer)
end
|
.latest_for_tag(tag) ⇒ Object
148
149
150
|
# File 'lib/pact_broker/pacts/selector.rb', line 148
def self.latest_for_tag(tag)
new(latest: true, tag: tag)
end
|
.latest_for_tag_and_consumer(tag, consumer) ⇒ Object
172
173
174
|
# File 'lib/pact_broker/pacts/selector.rb', line 172
def self.latest_for_tag_and_consumer(tag, consumer)
new(latest: true, tag: tag, consumer: consumer)
end
|
.latest_for_tag_with_fallback(tag, fallback_tag) ⇒ Object
156
157
158
|
# File 'lib/pact_broker/pacts/selector.rb', line 156
def self.latest_for_tag_with_fallback(tag, fallback_tag)
new(latest: true, tag: tag, fallback_tag: fallback_tag)
end
|
.overall_latest ⇒ Object
140
141
142
|
# File 'lib/pact_broker/pacts/selector.rb', line 140
def self.overall_latest
new(latest: true)
end
|
Instance Method Details
#<=>(other) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/pact_broker/pacts/selector.rb', line 287
def <=> other
if overall_latest? || other.overall_latest?
overall_latest_comparison(other)
elsif latest_for_branch? || other.latest_for_branch?
branch_comparison(other)
elsif latest_for_tag? || other.latest_for_tag?
latest_for_tag_comparison(other)
elsif tag || other.tag
tag_comparison(other)
elsif currently_deployed? || other.currently_deployed?
currently_deployed_comparison(other)
elsif currently_supported? || other.currently_supported?
currently_supported_comparison(other)
elsif consumer || other.consumer
consumer_comparison(other)
else
0
end
end
|
#==(other) ⇒ Object
282
283
284
|
# File 'lib/pact_broker/pacts/selector.rb', line 282
def == other
other.class == self.class && super
end
|
#all_for_tag? ⇒ Boolean
278
279
280
|
# File 'lib/pact_broker/pacts/selector.rb', line 278
def all_for_tag?
!!(tag && !latest?)
end
|
#all_for_tag_and_consumer? ⇒ Boolean
274
275
276
|
# File 'lib/pact_broker/pacts/selector.rb', line 274
def all_for_tag_and_consumer?
!!(tag && !latest? && consumer)
end
|
#branch ⇒ Object
240
241
242
|
# File 'lib/pact_broker/pacts/selector.rb', line 240
def branch
self[:branch]
end
|
#branch=(branch) ⇒ Object
68
69
70
|
# File 'lib/pact_broker/pacts/selector.rb', line 68
def branch= branch
self[:branch] = branch
end
|
#consumer ⇒ Object
100
101
102
|
# File 'lib/pact_broker/pacts/selector.rb', line 100
def consumer
self[:consumer]
end
|
#consumer=(consumer) ⇒ Object
96
97
98
|
# File 'lib/pact_broker/pacts/selector.rb', line 96
def consumer= consumer
self[:consumer] = consumer
end
|
#currently_deployed ⇒ Object
108
109
110
|
# File 'lib/pact_broker/pacts/selector.rb', line 108
def currently_deployed
self[:currently_deployed]
end
|
#currently_deployed=(currently_deployed) ⇒ Object
104
105
106
|
# File 'lib/pact_broker/pacts/selector.rb', line 104
def currently_deployed= currently_deployed
self[:currently_deployed] = currently_deployed
end
|
#currently_deployed? ⇒ Boolean
112
113
114
|
# File 'lib/pact_broker/pacts/selector.rb', line 112
def currently_deployed?
!!currently_deployed
end
|
#currently_supported ⇒ Object
120
121
122
|
# File 'lib/pact_broker/pacts/selector.rb', line 120
def currently_supported
self[:currently_supported]
end
|
#currently_supported=(currently_supported) ⇒ Object
116
117
118
|
# File 'lib/pact_broker/pacts/selector.rb', line 116
def currently_supported= currently_supported
self[:currently_supported] = currently_supported
end
|
#currently_supported? ⇒ Boolean
124
125
126
|
# File 'lib/pact_broker/pacts/selector.rb', line 124
def currently_supported?
!!currently_supported
end
|
#environment_name ⇒ Object
132
133
134
|
# File 'lib/pact_broker/pacts/selector.rb', line 132
def environment_name
self[:environment_name]
end
|
#environment_name=(environment_name) ⇒ Object
128
129
130
|
# File 'lib/pact_broker/pacts/selector.rb', line 128
def environment_name= environment_name
self[:environment_name] = environment_name
end
|
#fallback_branch ⇒ Object
92
93
94
|
# File 'lib/pact_broker/pacts/selector.rb', line 92
def fallback_branch
self[:fallback_branch]
end
|
#fallback_branch=(fallback_branch) ⇒ Object
84
85
86
|
# File 'lib/pact_broker/pacts/selector.rb', line 84
def fallback_branch= fallback_branch
self[:fallback_branch] = fallback_branch
end
|
#fallback_branch? ⇒ Boolean
228
229
230
|
# File 'lib/pact_broker/pacts/selector.rb', line 228
def fallback_branch?
!!fallback_branch
end
|
#fallback_tag ⇒ Object
88
89
90
|
# File 'lib/pact_broker/pacts/selector.rb', line 88
def fallback_tag
self[:fallback_tag]
end
|
#fallback_tag=(fallback_tag) ⇒ Object
80
81
82
|
# File 'lib/pact_broker/pacts/selector.rb', line 80
def fallback_tag= fallback_tag
self[:fallback_tag] = fallback_tag
end
|
#fallback_tag? ⇒ Boolean
224
225
226
|
# File 'lib/pact_broker/pacts/selector.rb', line 224
def fallback_tag?
!!fallback_tag
end
|
#for_consumer(consumer) ⇒ Object
216
217
218
|
# File 'lib/pact_broker/pacts/selector.rb', line 216
def for_consumer(consumer)
self.class.new(to_h.merge(consumer: consumer))
end
|
#in_environment? ⇒ Boolean
136
137
138
|
# File 'lib/pact_broker/pacts/selector.rb', line 136
def in_environment?
!!environment_name
end
|
#latest ⇒ Object
76
77
78
|
# File 'lib/pact_broker/pacts/selector.rb', line 76
def latest
self[:latest]
end
|
#latest=(latest) ⇒ Object
72
73
74
|
# File 'lib/pact_broker/pacts/selector.rb', line 72
def latest= latest
self[:latest] = latest
end
|
#latest_for_branch?(potential_branch = nil) ⇒ Boolean
Not sure if the fallback_tag logic is needed
266
267
268
269
270
271
272
|
# File 'lib/pact_broker/pacts/selector.rb', line 266
def latest_for_branch? potential_branch = nil
if potential_branch
!!(latest && branch == potential_branch)
else
!!(latest && !!branch)
end
end
|
#latest_for_main_branch? ⇒ Boolean
220
221
222
|
# File 'lib/pact_broker/pacts/selector.rb', line 220
def latest_for_main_branch?
!!main_branch
end
|
#latest_for_tag?(potential_tag = nil) ⇒ Boolean
Not sure if the fallback_tag logic is needed
257
258
259
260
261
262
263
|
# File 'lib/pact_broker/pacts/selector.rb', line 257
def latest_for_tag? potential_tag = nil
if potential_tag
!!(latest && tag == potential_tag)
else
!!(latest && !!tag)
end
end
|
#main_branch ⇒ Object
232
233
234
|
# File 'lib/pact_broker/pacts/selector.rb', line 232
def main_branch
self[:main_branch]
end
|
#main_branch=(main_branch) ⇒ Object
rubocop: enable Metrics/CyclomaticComplexity
56
57
58
|
# File 'lib/pact_broker/pacts/selector.rb', line 56
def main_branch= main_branch
self[:main_branch] = main_branch
end
|
#matching_branch ⇒ Object
244
245
246
|
# File 'lib/pact_broker/pacts/selector.rb', line 244
def matching_branch
self[:matching_branch]
end
|
#matching_branch=(matching_branch) ⇒ Object
60
61
62
|
# File 'lib/pact_broker/pacts/selector.rb', line 60
def matching_branch= matching_branch
self[:matching_branch] = matching_branch
end
|
#matching_branch? ⇒ Boolean
248
249
250
|
# File 'lib/pact_broker/pacts/selector.rb', line 248
def matching_branch?
!!matching_branch
end
|
#overall_latest? ⇒ Boolean
252
253
254
|
# File 'lib/pact_broker/pacts/selector.rb', line 252
def overall_latest?
!!(latest? && !tag && !branch && !main_branch && !currently_deployed && !currently_supported && !environment_name)
end
|
#resolve(consumer_version) ⇒ Object
16
17
18
|
# File 'lib/pact_broker/pacts/selector.rb', line 16
def resolve(consumer_version)
ResolvedSelector.new(self.to_h.without(:fallback_tag, :fallback_branch), consumer_version)
end
|
#resolve_for_environment(consumer_version, environment, target = nil) ⇒ Object
24
25
26
|
# File 'lib/pact_broker/pacts/selector.rb', line 24
def resolve_for_environment(consumer_version, environment, target = nil)
ResolvedSelector.new(self.to_h.merge({ environment: environment, target: target }.compact), consumer_version)
end
|
#resolve_for_fallback(consumer_version) ⇒ Object
20
21
22
|
# File 'lib/pact_broker/pacts/selector.rb', line 20
def resolve_for_fallback(consumer_version)
ResolvedSelector.new(self.to_h, consumer_version)
end
|
#tag ⇒ Object
236
237
238
|
# File 'lib/pact_broker/pacts/selector.rb', line 236
def tag
self[:tag]
end
|
#tag=(tag) ⇒ Object
64
65
66
|
# File 'lib/pact_broker/pacts/selector.rb', line 64
def tag= tag
self[:tag] = tag
end
|
#type ⇒ Object
Only currently used to identify the currently_deployed from the others in verifiable_pact_messages, so don’t need the “for_consumer” sub category rubocop: disable Metrics/CyclomaticComplexity
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/pact_broker/pacts/selector.rb', line 31
def type
if latest_for_main_branch?
:latest_for_main_branch
elsif latest_for_branch?
:latest_for_branch
elsif matching_branch?
:matching_branch
elsif currently_deployed?
:currently_deployed
elsif currently_supported?
:currently_supported
elsif in_environment?
:in_environment
elsif latest_for_tag?
:latest_for_tag
elsif all_for_tag?
:all_for_tag
elsif overall_latest?
:overall_latest
else
:undefined
end
end
|