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
166
167
168
|
# File 'lib/pact_broker/pacts/selector.rb', line 166
def self.all_for_tag(tag)
new(tag: tag)
end
|
.all_for_tag_and_consumer(tag, consumer) ⇒ Object
170
171
172
|
# File 'lib/pact_broker/pacts/selector.rb', line 170
def self.all_for_tag_and_consumer(tag, consumer)
new(tag: tag, consumer: consumer)
end
|
.for_currently_deployed(environment_name = nil) ⇒ Object
186
187
188
|
# File 'lib/pact_broker/pacts/selector.rb', line 186
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
194
195
196
|
# File 'lib/pact_broker/pacts/selector.rb', line 194
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
198
199
200
|
# File 'lib/pact_broker/pacts/selector.rb', line 198
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
190
191
192
|
# File 'lib/pact_broker/pacts/selector.rb', line 190
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
202
203
204
|
# File 'lib/pact_broker/pacts/selector.rb', line 202
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
206
207
208
|
# File 'lib/pact_broker/pacts/selector.rb', line 206
def self.for_environment(environment_name)
new(environment_name: environment_name)
end
|
.for_environment_and_consumer(environment_name, consumer) ⇒ Object
210
211
212
|
# File 'lib/pact_broker/pacts/selector.rb', line 210
def self.for_environment_and_consumer(environment_name, consumer)
new(environment_name: environment_name, consumer: consumer)
end
|
.for_main_branch ⇒ Object
146
147
148
|
# File 'lib/pact_broker/pacts/selector.rb', line 146
def self.for_main_branch
new(main_branch: true)
end
|
.from_hash(hash) ⇒ Object
214
215
216
|
# File 'lib/pact_broker/pacts/selector.rb', line 214
def self.from_hash hash
new(hash)
end
|
.latest_for_branch(branch) ⇒ Object
154
155
156
|
# File 'lib/pact_broker/pacts/selector.rb', line 154
def self.latest_for_branch(branch)
new(latest: true, branch: branch)
end
|
.latest_for_branch_and_consumer(branch, consumer) ⇒ Object
178
179
180
|
# File 'lib/pact_broker/pacts/selector.rb', line 178
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
162
163
164
|
# File 'lib/pact_broker/pacts/selector.rb', line 162
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
182
183
184
|
# File 'lib/pact_broker/pacts/selector.rb', line 182
def self.latest_for_consumer(consumer)
new(latest: true, consumer: consumer)
end
|
.latest_for_tag(tag) ⇒ Object
150
151
152
|
# File 'lib/pact_broker/pacts/selector.rb', line 150
def self.latest_for_tag(tag)
new(latest: true, tag: tag)
end
|
.latest_for_tag_and_consumer(tag, consumer) ⇒ Object
174
175
176
|
# File 'lib/pact_broker/pacts/selector.rb', line 174
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
158
159
160
|
# File 'lib/pact_broker/pacts/selector.rb', line 158
def self.latest_for_tag_with_fallback(tag, fallback_tag)
new(latest: true, tag: tag, fallback_tag: fallback_tag)
end
|
.overall_latest ⇒ Object
142
143
144
|
# File 'lib/pact_broker/pacts/selector.rb', line 142
def self.overall_latest
new(latest: true)
end
|
Instance Method Details
#<=>(other) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/pact_broker/pacts/selector.rb', line 293
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
288
289
290
|
# File 'lib/pact_broker/pacts/selector.rb', line 288
def == other
other.class == self.class && super
end
|
#all_for_tag? ⇒ Boolean
284
285
286
|
# File 'lib/pact_broker/pacts/selector.rb', line 284
def all_for_tag?
!!(tag && !latest?)
end
|
#all_for_tag_and_consumer? ⇒ Boolean
280
281
282
|
# File 'lib/pact_broker/pacts/selector.rb', line 280
def all_for_tag_and_consumer?
!!(tag && !latest? && consumer)
end
|
#branch ⇒ Object
242
243
244
|
# File 'lib/pact_broker/pacts/selector.rb', line 242
def branch
self[:branch]
end
|
#branch=(branch) ⇒ Object
70
71
72
|
# File 'lib/pact_broker/pacts/selector.rb', line 70
def branch= branch
self[:branch] = branch
end
|
#consumer ⇒ Object
102
103
104
|
# File 'lib/pact_broker/pacts/selector.rb', line 102
def consumer
self[:consumer]
end
|
#consumer=(consumer) ⇒ Object
98
99
100
|
# File 'lib/pact_broker/pacts/selector.rb', line 98
def consumer= consumer
self[:consumer] = consumer
end
|
#currently_deployed ⇒ Object
110
111
112
|
# File 'lib/pact_broker/pacts/selector.rb', line 110
def currently_deployed
self[:currently_deployed]
end
|
#currently_deployed=(currently_deployed) ⇒ Object
106
107
108
|
# File 'lib/pact_broker/pacts/selector.rb', line 106
def currently_deployed= currently_deployed
self[:currently_deployed] = currently_deployed
end
|
#currently_deployed? ⇒ Boolean
114
115
116
|
# File 'lib/pact_broker/pacts/selector.rb', line 114
def currently_deployed?
!!currently_deployed
end
|
#currently_supported ⇒ Object
122
123
124
|
# File 'lib/pact_broker/pacts/selector.rb', line 122
def currently_supported
self[:currently_supported]
end
|
#currently_supported=(currently_supported) ⇒ Object
118
119
120
|
# File 'lib/pact_broker/pacts/selector.rb', line 118
def currently_supported= currently_supported
self[:currently_supported] = currently_supported
end
|
#currently_supported? ⇒ Boolean
126
127
128
|
# File 'lib/pact_broker/pacts/selector.rb', line 126
def currently_supported?
!!currently_supported
end
|
#environment_name ⇒ Object
134
135
136
|
# File 'lib/pact_broker/pacts/selector.rb', line 134
def environment_name
self[:environment_name]
end
|
#environment_name=(environment_name) ⇒ Object
130
131
132
|
# File 'lib/pact_broker/pacts/selector.rb', line 130
def environment_name= environment_name
self[:environment_name] = environment_name
end
|
#fallback_branch ⇒ Object
94
95
96
|
# File 'lib/pact_broker/pacts/selector.rb', line 94
def fallback_branch
self[:fallback_branch]
end
|
#fallback_branch=(fallback_branch) ⇒ Object
86
87
88
|
# File 'lib/pact_broker/pacts/selector.rb', line 86
def fallback_branch= fallback_branch
self[:fallback_branch] = fallback_branch
end
|
#fallback_branch? ⇒ Boolean
230
231
232
|
# File 'lib/pact_broker/pacts/selector.rb', line 230
def fallback_branch?
!!fallback_branch
end
|
#fallback_tag ⇒ Object
90
91
92
|
# File 'lib/pact_broker/pacts/selector.rb', line 90
def fallback_tag
self[:fallback_tag]
end
|
#fallback_tag=(fallback_tag) ⇒ Object
82
83
84
|
# File 'lib/pact_broker/pacts/selector.rb', line 82
def fallback_tag= fallback_tag
self[:fallback_tag] = fallback_tag
end
|
#fallback_tag? ⇒ Boolean
226
227
228
|
# File 'lib/pact_broker/pacts/selector.rb', line 226
def fallback_tag?
!!fallback_tag
end
|
#for_consumer(consumer) ⇒ Object
218
219
220
|
# File 'lib/pact_broker/pacts/selector.rb', line 218
def for_consumer(consumer)
self.class.new(to_h.merge(consumer: consumer))
end
|
#in_environment? ⇒ Boolean
138
139
140
|
# File 'lib/pact_broker/pacts/selector.rb', line 138
def in_environment?
!!environment_name
end
|
#latest ⇒ Object
78
79
80
|
# File 'lib/pact_broker/pacts/selector.rb', line 78
def latest
self[:latest]
end
|
#latest=(latest) ⇒ Object
74
75
76
|
# File 'lib/pact_broker/pacts/selector.rb', line 74
def latest= latest
self[:latest] = latest
end
|
#latest_for_branch?(potential_branch = nil) ⇒ Boolean
Not sure if the fallback_tag logic is needed
268
269
270
271
272
273
274
|
# File 'lib/pact_broker/pacts/selector.rb', line 268
def latest_for_branch? potential_branch = nil
if potential_branch
latest == true && branch == potential_branch
else
latest == true && branch.is_a?(String)
end
end
|
#latest_for_each_branch? ⇒ Boolean
276
277
278
|
# File 'lib/pact_broker/pacts/selector.rb', line 276
def latest_for_each_branch?
latest == true && branch == true
end
|
#latest_for_main_branch? ⇒ Boolean
222
223
224
|
# File 'lib/pact_broker/pacts/selector.rb', line 222
def latest_for_main_branch?
!!main_branch
end
|
#latest_for_tag?(potential_tag = nil) ⇒ Boolean
Not sure if the fallback_tag logic is needed
259
260
261
262
263
264
265
|
# File 'lib/pact_broker/pacts/selector.rb', line 259
def latest_for_tag? potential_tag = nil
if potential_tag
!!(latest && tag == potential_tag)
else
!!(latest && !!tag)
end
end
|
#main_branch ⇒ Object
234
235
236
|
# File 'lib/pact_broker/pacts/selector.rb', line 234
def main_branch
self[:main_branch]
end
|
#main_branch=(main_branch) ⇒ Object
rubocop: enable Metrics/CyclomaticComplexity
58
59
60
|
# File 'lib/pact_broker/pacts/selector.rb', line 58
def main_branch= main_branch
self[:main_branch] = main_branch
end
|
#matching_branch ⇒ Object
246
247
248
|
# File 'lib/pact_broker/pacts/selector.rb', line 246
def matching_branch
self[:matching_branch]
end
|
#matching_branch=(matching_branch) ⇒ Object
62
63
64
|
# File 'lib/pact_broker/pacts/selector.rb', line 62
def matching_branch= matching_branch
self[:matching_branch] = matching_branch
end
|
#matching_branch? ⇒ Boolean
250
251
252
|
# File 'lib/pact_broker/pacts/selector.rb', line 250
def matching_branch?
!!matching_branch
end
|
#overall_latest? ⇒ Boolean
254
255
256
|
# File 'lib/pact_broker/pacts/selector.rb', line 254
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
238
239
240
|
# File 'lib/pact_broker/pacts/selector.rb', line 238
def tag
self[:tag]
end
|
#tag=(tag) ⇒ Object
66
67
68
|
# File 'lib/pact_broker/pacts/selector.rb', line 66
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
54
55
|
# File 'lib/pact_broker/pacts/selector.rb', line 31
def type
if latest_for_main_branch?
:latest_for_main_branch
elsif latest_for_each_branch?
:latest_for_each_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
|