Class: PactBroker::Pacts::Selector

Inherits:
Hash
  • Object
show all
Defined in:
lib/pact_broker/pacts/selector.rb

Direct Known Subclasses

ResolvedSelector

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Selector

Returns a new instance of Selector.



8
9
10
# File 'lib/pact_broker/pacts/selector.rb', line 8

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

Class Method Details

.all_for_tag(tag) ⇒ Object



80
81
82
# File 'lib/pact_broker/pacts/selector.rb', line 80

def self.all_for_tag(tag)
  Selector.new(tag: tag)
end

.all_for_tag_and_consumer(tag, consumer) ⇒ Object



84
85
86
# File 'lib/pact_broker/pacts/selector.rb', line 84

def self.all_for_tag_and_consumer(tag, consumer)
  Selector.new(tag: tag, consumer: consumer)
end

.from_hash(hash) ⇒ Object



100
101
102
# File 'lib/pact_broker/pacts/selector.rb', line 100

def self.from_hash hash
  Selector.new(hash)
end

.latest_for_branch(branch) ⇒ Object



68
69
70
# File 'lib/pact_broker/pacts/selector.rb', line 68

def self.latest_for_branch(branch)
  Selector.new(latest: true, branch: branch)
end

.latest_for_branch_and_consumer(branch, consumer) ⇒ Object



92
93
94
# File 'lib/pact_broker/pacts/selector.rb', line 92

def self.latest_for_branch_and_consumer(branch, consumer)
  Selector.new(latest: true, branch: branch, consumer: consumer)
end

.latest_for_branch_with_fallback(branch, fallback_branch) ⇒ Object



76
77
78
# File 'lib/pact_broker/pacts/selector.rb', line 76

def self.latest_for_branch_with_fallback(branch, fallback_branch)
  Selector.new(latest: true, branch: branch, fallback_branch: fallback_branch)
end

.latest_for_consumer(consumer) ⇒ Object



96
97
98
# File 'lib/pact_broker/pacts/selector.rb', line 96

def self.latest_for_consumer(consumer)
  Selector.new(latest: true, consumer: consumer)
end

.latest_for_tag(tag) ⇒ Object



64
65
66
# File 'lib/pact_broker/pacts/selector.rb', line 64

def self.latest_for_tag(tag)
  Selector.new(latest: true, tag: tag)
end

.latest_for_tag_and_consumer(tag, consumer) ⇒ Object



88
89
90
# File 'lib/pact_broker/pacts/selector.rb', line 88

def self.latest_for_tag_and_consumer(tag, consumer)
  Selector.new(latest: true, tag: tag, consumer: consumer)
end

.latest_for_tag_with_fallback(tag, fallback_tag) ⇒ Object



72
73
74
# File 'lib/pact_broker/pacts/selector.rb', line 72

def self.latest_for_tag_with_fallback(tag, fallback_tag)
  Selector.new(latest: true, tag: tag, fallback_tag: fallback_tag)
end

.overall_latestObject



60
61
62
# File 'lib/pact_broker/pacts/selector.rb', line 60

def self.overall_latest
  Selector.new(latest: true)
end

Instance Method Details

#<=>(other) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/pact_broker/pacts/selector.rb', line 154

def <=> other
  if overall_latest? || other.overall_latest?
    if overall_latest? == other.overall_latest?
      0
    else
      overall_latest? ? -1 : 1
    end
  elsif latest_for_branch? || other.latest_for_branch?
    if latest_for_branch? == other.latest_for_branch?
      branch <=> other.branch
    else
      latest_for_branch? ? -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
  elsif consumer || other.consumer
    if consumer == other.consumer
      tag <=> other.tag
    else
      consumer ? -1 : 1
    end
  else
    tag <=> other.tag
  end
end

#==(other) ⇒ Object



150
151
152
# File 'lib/pact_broker/pacts/selector.rb', line 150

def == other
  other.class == self.class && super
end

#all_for_tag?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/pact_broker/pacts/selector.rb', line 146

def all_for_tag?
  !!(tag && !latest?)
end

#all_for_tag_and_consumer?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/pact_broker/pacts/selector.rb', line 142

def all_for_tag_and_consumer?
  !!(tag && !latest? && consumer)
end

#branchObject



116
117
118
# File 'lib/pact_broker/pacts/selector.rb', line 116

def branch
  self[:branch]
end

#branch=(branch) ⇒ Object



24
25
26
# File 'lib/pact_broker/pacts/selector.rb', line 24

def branch= branch
  self[:branch] = branch
end

#consumerObject



56
57
58
# File 'lib/pact_broker/pacts/selector.rb', line 56

def consumer
  self[:consumer]
end

#consumer=(consumer) ⇒ Object



52
53
54
# File 'lib/pact_broker/pacts/selector.rb', line 52

def consumer= consumer
  self[:consumer] = consumer
end

#fallback_branchObject



48
49
50
# File 'lib/pact_broker/pacts/selector.rb', line 48

def fallback_branch
  self[:fallback_branch]
end

#fallback_branch=(fallback_branch) ⇒ Object



40
41
42
# File 'lib/pact_broker/pacts/selector.rb', line 40

def fallback_branch= fallback_branch
  self[:fallback_branch] = fallback_branch
end

#fallback_branch?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/pact_broker/pacts/selector.rb', line 108

def fallback_branch?
  !!fallback_branch
end

#fallback_tagObject



44
45
46
# File 'lib/pact_broker/pacts/selector.rb', line 44

def fallback_tag
  self[:fallback_tag]
end

#fallback_tag=(fallback_tag) ⇒ Object



36
37
38
# File 'lib/pact_broker/pacts/selector.rb', line 36

def fallback_tag= fallback_tag
  self[:fallback_tag] = fallback_tag
end

#fallback_tag?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/pact_broker/pacts/selector.rb', line 104

def fallback_tag?
  !!fallback_tag
end

#latestObject



32
33
34
# File 'lib/pact_broker/pacts/selector.rb', line 32

def latest
  self[:latest]
end

#latest=(latest) ⇒ Object



28
29
30
# File 'lib/pact_broker/pacts/selector.rb', line 28

def latest= latest
  self[:latest] = latest
end

#latest_for_branch?(potential_branch = nil) ⇒ Boolean

Not sure if the fallback_tag logic is needed

Returns:

  • (Boolean)


134
135
136
137
138
139
140
# File 'lib/pact_broker/pacts/selector.rb', line 134

def latest_for_branch? potential_branch = nil
  if potential_branch
    !!(latest && branch == potential_branch)
  else
    !!(latest && !!branch)
  end
end

#latest_for_tag?(potential_tag = nil) ⇒ Boolean

Not sure if the fallback_tag logic is needed

Returns:

  • (Boolean)


125
126
127
128
129
130
131
# File 'lib/pact_broker/pacts/selector.rb', line 125

def latest_for_tag? potential_tag = nil
  if potential_tag
    !!(latest && tag == potential_tag)
  else
    !!(latest && !!tag)
  end
end

#overall_latest?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/pact_broker/pacts/selector.rb', line 120

def overall_latest?
  !!(latest? && !tag && !branch)
end

#resolve(consumer_version) ⇒ Object



12
13
14
# File 'lib/pact_broker/pacts/selector.rb', line 12

def resolve(consumer_version)
  ResolvedSelector.new(self.to_h.without(:fallback_tag, :fallback_branch), consumer_version)
end

#resolve_for_fallback(consumer_version) ⇒ Object



16
17
18
# File 'lib/pact_broker/pacts/selector.rb', line 16

def resolve_for_fallback(consumer_version)
  ResolvedSelector.new(self.to_h, consumer_version)
end

#tagObject



112
113
114
# File 'lib/pact_broker/pacts/selector.rb', line 112

def tag
  self[:tag]
end

#tag=(tag) ⇒ Object



20
21
22
# File 'lib/pact_broker/pacts/selector.rb', line 20

def tag= tag
  self[:tag] = tag
end