class PactBroker::Pacts::Selector
rubocop: disable Metrics/ClassLength
Constants
- PROPERTY_NAMES
Public Class Methods
Source
# File lib/pact_broker/pacts/selector.rb, line 170 def self.all_for_tag(tag) new(tag: tag) end
Source
# File lib/pact_broker/pacts/selector.rb, line 174 def self.all_for_tag_and_consumer(tag, consumer) new(tag: tag, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 190 def self.for_currently_deployed(environment_name = nil) new( { currently_deployed: true, environment_name: environment_name }.compact ) end
Source
# File lib/pact_broker/pacts/selector.rb, line 198 def self.for_currently_deployed_and_consumer(consumer) new(currently_deployed: true, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 202 def self.for_currently_deployed_and_environment_and_consumer(environment_name, consumer) new(currently_deployed: true, environment_name: environment_name, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 194 def self.for_currently_supported(environment_name = nil) new( { currently_supported: true, environment_name: environment_name }.compact ) end
Source
# File lib/pact_broker/pacts/selector.rb, line 206 def self.for_currently_supported_and_environment_and_consumer(environment_name, consumer) new(currently_supported: true, environment_name: environment_name, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 210 def self.for_environment(environment_name) new(environment_name: environment_name) end
Source
# File lib/pact_broker/pacts/selector.rb, line 214 def self.for_environment_and_consumer(environment_name, consumer) new(environment_name: environment_name, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 146 def self.for_main_branch new(main_branch: true) end
Source
# File lib/pact_broker/pacts/selector.rb, line 218 def self.from_hash hash new(hash) end
Source
# File lib/pact_broker/pacts/selector.rb, line 154 def self.latest_for_branch(branch) new(latest: true, branch: branch) end
Source
# File lib/pact_broker/pacts/selector.rb, line 182 def self.latest_for_branch_and_consumer(branch, consumer) new(latest: true, branch: branch, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 166 def self.latest_for_branch_with_fallback(branch, fallback_branch) new(latest: true, branch: branch, fallback_branch: fallback_branch) end
Source
# File lib/pact_broker/pacts/selector.rb, line 186 def self.latest_for_consumer(consumer) new(latest: true, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 158 def self.latest_for_main_branch new(latest: true, main_branch: true) end
Source
# File lib/pact_broker/pacts/selector.rb, line 150 def self.latest_for_tag(tag) new(latest: true, tag: tag) end
Source
# File lib/pact_broker/pacts/selector.rb, line 178 def self.latest_for_tag_and_consumer(tag, consumer) new(latest: true, tag: tag, consumer: consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 162 def self.latest_for_tag_with_fallback(tag, fallback_tag) new(latest: true, tag: tag, fallback_tag: fallback_tag) end
Source
# 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
Source
# File lib/pact_broker/pacts/selector.rb, line 142 def self.overall_latest new(latest: true) end
Public Instance Methods
Source
# File lib/pact_broker/pacts/selector.rb, line 297 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
rubocop: disable Metrics/CyclomaticComplexity
Source
# File lib/pact_broker/pacts/selector.rb, line 292 def == other other.class == self.class && super end
Calls superclass method
Source
# File lib/pact_broker/pacts/selector.rb, line 288 def all_for_tag? !!(tag && !latest?) end
Source
# File lib/pact_broker/pacts/selector.rb, line 284 def all_for_tag_and_consumer? !!(tag && !latest? && consumer) end
Source
# File lib/pact_broker/pacts/selector.rb, line 70 def branch= branch self[:branch] = branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 102 def consumer self[:consumer] end
Source
# File lib/pact_broker/pacts/selector.rb, line 98 def consumer= consumer self[:consumer] = consumer end
Source
# File lib/pact_broker/pacts/selector.rb, line 110 def currently_deployed self[:currently_deployed] end
Source
# File lib/pact_broker/pacts/selector.rb, line 106 def currently_deployed= currently_deployed self[:currently_deployed] = currently_deployed end
Source
# File lib/pact_broker/pacts/selector.rb, line 114 def currently_deployed? !!currently_deployed end
Source
# File lib/pact_broker/pacts/selector.rb, line 122 def currently_supported self[:currently_supported] end
Source
# File lib/pact_broker/pacts/selector.rb, line 118 def currently_supported= currently_supported self[:currently_supported] = currently_supported end
Source
# File lib/pact_broker/pacts/selector.rb, line 126 def currently_supported? !!currently_supported end
Source
# File lib/pact_broker/pacts/selector.rb, line 134 def environment_name self[:environment_name] end
Source
# File lib/pact_broker/pacts/selector.rb, line 130 def environment_name= environment_name self[:environment_name] = environment_name end
Source
# File lib/pact_broker/pacts/selector.rb, line 94 def fallback_branch self[:fallback_branch] end
Source
# File lib/pact_broker/pacts/selector.rb, line 86 def fallback_branch= fallback_branch self[:fallback_branch] = fallback_branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 234 def fallback_branch? !!fallback_branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 90 def fallback_tag self[:fallback_tag] end
Source
# File lib/pact_broker/pacts/selector.rb, line 82 def fallback_tag= fallback_tag self[:fallback_tag] = fallback_tag end
Source
# File lib/pact_broker/pacts/selector.rb, line 230 def fallback_tag? !!fallback_tag end
Source
# File lib/pact_broker/pacts/selector.rb, line 222 def for_consumer(consumer) self.class.new(to_h.merge(consumer: consumer)) end
Source
# File lib/pact_broker/pacts/selector.rb, line 138 def in_environment? !!environment_name end
Source
# File lib/pact_broker/pacts/selector.rb, line 74 def latest= latest self[:latest] = latest end
Source
# File lib/pact_broker/pacts/selector.rb, line 272 def latest_for_branch? potential_branch = nil if potential_branch latest == true && branch == potential_branch else latest == true && branch.is_a?(String) end end
Not sure if the fallback_tag
logic is needed
Source
# File lib/pact_broker/pacts/selector.rb, line 280 def latest_for_each_branch? latest == true && branch == true end
Source
# File lib/pact_broker/pacts/selector.rb, line 226 def latest_for_main_branch? !!main_branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 263 def latest_for_tag? potential_tag = nil if potential_tag !!(latest && tag == potential_tag) else !!(latest && !!tag) end end
Not sure if the fallback_tag
logic is needed
Source
# File lib/pact_broker/pacts/selector.rb, line 238 def main_branch self[:main_branch] end
Source
# File lib/pact_broker/pacts/selector.rb, line 58 def main_branch= main_branch self[:main_branch] = main_branch end
rubocop: enable Metrics/CyclomaticComplexity
Source
# File lib/pact_broker/pacts/selector.rb, line 250 def matching_branch self[:matching_branch] end
Source
# File lib/pact_broker/pacts/selector.rb, line 62 def matching_branch= matching_branch self[:matching_branch] = matching_branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 254 def matching_branch? !!matching_branch end
Source
# File lib/pact_broker/pacts/selector.rb, line 258 def overall_latest? !!(latest? && !tag && !branch && !main_branch && !currently_deployed && !currently_supported && !environment_name) end
Source
# 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
Source
# 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
Source
# File lib/pact_broker/pacts/selector.rb, line 20 def resolve_for_fallback(consumer_version) ResolvedSelector.new(self.to_h, consumer_version) end
Source
# File lib/pact_broker/pacts/selector.rb, line 66 def tag= tag self[:tag] = tag end
Source
# 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
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
Private Instance Methods
Source
# File lib/pact_broker/pacts/selector.rb, line 328 def branch_comparison(other) if latest_for_branch? == other.latest_for_branch? branch <=> other.branch else latest_for_branch? ? -1 : 1 end end
Source
# File lib/pact_broker/pacts/selector.rb, line 372 def consumer_comparison(other) if consumer && other.consumer consumer <=> other.consumer else consumer ? -1 : 1 end end
Source
# File lib/pact_broker/pacts/selector.rb, line 336 def currently_deployed_comparison(other) if currently_deployed? == other.currently_deployed? environment_name <=> other.environment_name else currently_deployed? ? -1 : 1 end end
Source
# File lib/pact_broker/pacts/selector.rb, line 344 def currently_supported_comparison(other) if currently_supported? == other.currently_supported? environment_name <=> other.environment_name else currently_supported? ? -1 : 1 end end
Source
# File lib/pact_broker/pacts/selector.rb, line 380 def latest? !!self[:latest] end
Source
# File lib/pact_broker/pacts/selector.rb, line 352 def latest_for_tag_comparison(other) if latest_for_tag? == other.latest_for_tag? tag <=> other.tag else latest_for_tag? ? -1 : 1 end end
Source
# File lib/pact_broker/pacts/selector.rb, line 320 def overall_latest_comparison(other) if overall_latest? == other.overall_latest? 0 else overall_latest? ? -1 : 1 end end
rubocop: enable Metrics/CyclomaticComplexity
Source
# File lib/pact_broker/pacts/selector.rb, line 360 def tag_comparison(other) if tag && other.tag if tag == other.tag consumer_comparison(other) else tag <=> other.tag end else tag ? -1 : 1 end end