/
selector.rb
65 lines (54 loc) · 1.18 KB
/
selector.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
61
62
63
64
65
module PactBroker
module Pacts
class Selector < Hash
def initialize(options)
merge!(options)
end
def self.overall_latest
Selector.new(latest: true)
end
def self.latest_for_tag(tag)
Selector.new(latest: true, tag: tag)
end
def self.all_for_tag(tag)
Selector.new(tag: tag)
end
def self.from_hash hash
Selector.new(hash)
end
def tag
self[:tag]
end
def overall_latest?
!!(latest? && !tag)
end
def latest_for_tag?
!!(latest && tag)
end
def <=> other
if overall_latest? || other.overall_latest?
if overall_latest? == other.overall_latest?
0
else
overall_latest? ? -1 : 1
end
elsif latest_for_tag? || other.latest_for_tag?
if latest_for_tag? == other.latest_for_tag?
tag <=> other.tag
else
latest_for_tag? ? -1 : 1
end
else
tag <=> other.tag
end
end
private
def latest?
self[:latest]
end
def latest
self[:latest]
end
end
end
end