class PactBroker::Pacts::Selector

rubocop: disable Metrics/ClassLength

Constants

PROPERTY_NAMES

Public Class Methods

all_for_tag(tag) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 162
def self.all_for_tag(tag)
  new(tag: tag)
end
all_for_tag_and_consumer(tag, consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 166
def self.all_for_tag_and_consumer(tag, consumer)
  new(tag: tag, consumer: consumer)
end
for_currently_deployed(environment_name = nil) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 182
def self.for_currently_deployed(environment_name = nil)
  new( { currently_deployed: true, environment_name: environment_name }.compact )
end
for_currently_deployed_and_consumer(consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 190
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 194
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 186
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 198
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 202
def self.for_environment(environment_name)
  new(environment_name: environment_name)
end
for_environment_and_consumer(environment_name, consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 206
def self.for_environment_and_consumer(environment_name, consumer)
  new(environment_name: environment_name, consumer: consumer)
end
for_main_branch() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 142
def self.for_main_branch
  new(main_branch: true)
end
from_hash(hash) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 210
def self.from_hash hash
  new(hash)
end
latest_for_branch(branch) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 150
def self.latest_for_branch(branch)
  new(latest: true, branch: branch)
end
latest_for_branch_and_consumer(branch, consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 174
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 158
def self.latest_for_branch_with_fallback(branch, fallback_branch)
  new(latest: true, branch: branch, fallback_branch: fallback_branch)
end
latest_for_consumer(consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 178
def self.latest_for_consumer(consumer)
  new(latest: true, consumer: consumer)
end
latest_for_tag(tag) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 146
def self.latest_for_tag(tag)
  new(latest: true, tag: tag)
end
latest_for_tag_and_consumer(tag, consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 170
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) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 154
def self.latest_for_tag_with_fallback(tag, fallback_tag)
  new(latest: true, tag: tag, fallback_tag: fallback_tag)
end
new(properties = {}) click to toggle 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
overall_latest() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 138
def self.overall_latest
  new(latest: true)
end

Public Instance Methods

<=>(other) click to toggle source

rubocop: disable Metrics/CyclomaticComplexity

# File lib/pact_broker/pacts/selector.rb, line 285
def <=> other
  # elsif consumer || other.consumer
  #   consumer_comparison(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)
  else
    0
  end
end
==(other) click to toggle source
Calls superclass method
# File lib/pact_broker/pacts/selector.rb, line 280
def == other
  other.class == self.class && super
end
all_for_tag?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 276
def all_for_tag?
  !!(tag && !latest?)
end
all_for_tag_and_consumer?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 272
def all_for_tag_and_consumer?
  !!(tag && !latest? && consumer)
end
branch() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 238
def branch
  self[:branch]
end
branch=(branch) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 66
def branch= branch
  self[:branch] = branch
end
consumer() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 98
def consumer
  self[:consumer]
end
consumer=(consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 94
def consumer= consumer
  self[:consumer] = consumer
end
currently_deployed() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 106
def currently_deployed
  self[:currently_deployed]
end
currently_deployed=(currently_deployed) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 102
def currently_deployed= currently_deployed
  self[:currently_deployed] = currently_deployed
end
currently_deployed?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 110
def currently_deployed?
  !!currently_deployed
end
currently_supported() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 118
def currently_supported
  self[:currently_supported]
end
currently_supported=(currently_supported) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 114
def currently_supported= currently_supported
  self[:currently_supported] = currently_supported
end
currently_supported?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 122
def currently_supported?
  !!currently_supported
end
environment_name() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 130
def environment_name
  self[:environment_name]
end
environment_name=(environment_name) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 126
def environment_name= environment_name
  self[:environment_name] = environment_name
end
fallback_branch() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 90
def fallback_branch
  self[:fallback_branch]
end
fallback_branch=(fallback_branch) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 82
def fallback_branch= fallback_branch
  self[:fallback_branch] = fallback_branch
end
fallback_branch?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 226
def fallback_branch?
  !!fallback_branch
end
fallback_tag() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 86
def fallback_tag
  self[:fallback_tag]
end
fallback_tag=(fallback_tag) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 78
def fallback_tag= fallback_tag
  self[:fallback_tag] = fallback_tag
end
fallback_tag?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 222
def fallback_tag?
  !!fallback_tag
end
for_consumer(consumer) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 214
def for_consumer(consumer)
  self.class.new(to_h.merge(consumer: consumer))
end
in_environment?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 134
def in_environment?
  !!environment_name
end
latest() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 74
def latest
  self[:latest]
end
latest=(latest) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 70
def latest= latest
  self[:latest] = latest
end
latest_for_branch?(potential_branch = nil) click to toggle source

Not sure if the fallback_tag logic is needed

# File lib/pact_broker/pacts/selector.rb, line 264
def latest_for_branch? potential_branch = nil
  if potential_branch
    !!(latest && branch == potential_branch)
  else
    !!(latest && !!branch)
  end
end
latest_for_main_branch?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 218
def latest_for_main_branch?
  !!main_branch
end
latest_for_tag?(potential_tag = nil) click to toggle source

Not sure if the fallback_tag logic is needed

# File lib/pact_broker/pacts/selector.rb, line 255
def latest_for_tag? potential_tag = nil
  if potential_tag
    !!(latest && tag == potential_tag)
  else
    !!(latest && !!tag)
  end
end
main_branch() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 230
def main_branch
  self[:main_branch]
end
main_branch=(main_branch) click to toggle source

rubocop: enable Metrics/CyclomaticComplexity

# File lib/pact_broker/pacts/selector.rb, line 54
def main_branch= main_branch
  self[:main_branch] = main_branch
end
matching_branch() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 242
def matching_branch
  self[:matching_branch]
end
matching_branch=(matching_branch) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 58
def matching_branch= matching_branch
  self[:matching_branch] = matching_branch
end
matching_branch?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 246
def matching_branch?
  !!matching_branch
end
overall_latest?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 250
def overall_latest?
  !!(latest? && !tag && !branch && !main_branch && !currently_deployed && !currently_supported && !environment_name)
end
resolve(consumer_version) click to toggle 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
resolve_for_environment(consumer_version, environment, target = nil) click to toggle 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
resolve_for_fallback(consumer_version) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 20
def resolve_for_fallback(consumer_version)
  ResolvedSelector.new(self.to_h, consumer_version)
end
tag() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 234
def tag
  self[:tag]
end
tag=(tag) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 62
def tag= tag
  self[:tag] = tag
end
type() click to toggle source

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

# File lib/pact_broker/pacts/selector.rb, line 31
def type
  if 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

Private Instance Methods

branch_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 316
def branch_comparison(other)
  if latest_for_branch? == other.latest_for_branch?
    branch <=> other.branch
  else
    latest_for_branch? ? -1 : 1
  end
end
consumer_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 360
def consumer_comparison(other)
  if consumer == other.consumer
    0
  else
    consumer ? -1 : 1
  end
end
currently_deployed_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 324
def currently_deployed_comparison(other)
  if currently_deployed? == other.currently_deployed?
    environment_name <=> other.environment_name
  else
    currently_deployed? ? -1 : 1
  end
end
currently_supported_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 332
def currently_supported_comparison(other)
  if currently_supported? == other.currently_supported?
    environment_name <=> other.environment_name
  else
    currently_supported? ? -1 : 1
  end
end
latest?() click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 368
def latest?
  !!self[:latest]
end
latest_for_tag_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 340
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
overall_latest_comparison(other) click to toggle source

rubocop: enable Metrics/CyclomaticComplexity

# File lib/pact_broker/pacts/selector.rb, line 308
def overall_latest_comparison(other)
  if overall_latest? == other.overall_latest?
    0
  else
    overall_latest? ? -1 : 1
  end
end
tag_comparison(other) click to toggle source
# File lib/pact_broker/pacts/selector.rb, line 348
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