Class: PactBroker::Pacts::ResolvedSelector

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

Constant Summary collapse

PROPERTY_NAMES =
Selector::PROPERTY_NAMES + [:consumer_version, :environment, :target]

Instance Method Summary collapse

Methods inherited from Selector

all_for_tag, #all_for_tag?, all_for_tag_and_consumer, #all_for_tag_and_consumer?, #branch, #branch=, #consumer, #consumer=, #currently_deployed, #currently_deployed=, #currently_deployed?, #currently_supported, #currently_supported=, #currently_supported?, #environment_name, #environment_name=, #fallback_branch, #fallback_branch=, #fallback_branch?, #fallback_tag, #fallback_tag=, #fallback_tag?, #for_consumer, for_currently_deployed, for_currently_deployed_and_consumer, for_currently_deployed_and_environment_and_consumer, for_currently_supported, for_currently_supported_and_environment_and_consumer, for_environment, for_environment_and_consumer, for_main_branch, from_hash, #in_environment?, #latest, #latest=, latest_for_branch, #latest_for_branch?, latest_for_branch_and_consumer, latest_for_branch_with_fallback, latest_for_consumer, #latest_for_main_branch?, latest_for_tag, #latest_for_tag?, latest_for_tag_and_consumer, latest_for_tag_with_fallback, #main_branch, #main_branch=, overall_latest, #overall_latest?, #resolve, #resolve_for_environment, #resolve_for_fallback, #tag, #tag=, #type

Constructor Details

#initialize(properties = {}, consumer_version) ⇒ ResolvedSelector

Returns a new instance of ResolvedSelector.



364
365
366
367
# File 'lib/pact_broker/pacts/selector.rb', line 364

def initialize(properties = {}, consumer_version)
  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.merge(consumer_version: consumer_version))
end

Instance Method Details

#<=>(other) ⇒ Object



381
382
383
384
385
386
387
388
# File 'lib/pact_broker/pacts/selector.rb', line 381

def <=> other
  comparison = super
  if comparison == 0
    consumer_version.order <=> other.consumer_version.order
  else
    comparison
  end
end

#==(other) ⇒ Object



377
378
379
# File 'lib/pact_broker/pacts/selector.rb', line 377

def == other
  super && consumer_version == other.consumer_version
end

#consumer_versionObject



369
370
371
# File 'lib/pact_broker/pacts/selector.rb', line 369

def consumer_version
  self[:consumer_version]
end

#currently_deployed_comparison(other) ⇒ Object



390
391
392
393
394
395
396
397
# File 'lib/pact_broker/pacts/selector.rb', line 390

def currently_deployed_comparison(other)
  if currently_deployed? == other.currently_deployed?
    production_comparison(other)
  else
    currently_deployed? ? -1 : 1
  end

end

#currently_supported_comparison(other) ⇒ Object



399
400
401
402
403
404
405
# File 'lib/pact_broker/pacts/selector.rb', line 399

def currently_supported_comparison(other)
  if currently_supported? == other.currently_supported?
    production_comparison(other)
  else
    currently_supported? ? -1 : 1
  end
end

#environmentObject



373
374
375
# File 'lib/pact_broker/pacts/selector.rb', line 373

def environment
  self[:environment]
end

#production_comparison(other) ⇒ Object



407
408
409
410
411
412
413
# File 'lib/pact_broker/pacts/selector.rb', line 407

def production_comparison(other)
  if environment.production? == other.environment.production?
    environment.name <=> other.environment.name
  else
    environment.production? ? 1 : -1
  end
end