Class: PactBroker::Pacts::ResolvedSelector

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

Direct Known Subclasses

Versions::ResolvedSelector

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=, #matching_branch, #matching_branch=, #matching_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.



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

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



395
396
397
398
399
400
401
402
# File 'lib/pact_broker/pacts/selector.rb', line 395

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

#==(other) ⇒ Object



391
392
393
# File 'lib/pact_broker/pacts/selector.rb', line 391

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

#consumer_versionObject



383
384
385
# File 'lib/pact_broker/pacts/selector.rb', line 383

def consumer_version
  self[:consumer_version]
end

#currently_deployed_comparison(other) ⇒ Object



404
405
406
407
408
409
410
411
# File 'lib/pact_broker/pacts/selector.rb', line 404

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



413
414
415
416
417
418
419
# File 'lib/pact_broker/pacts/selector.rb', line 413

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

#environmentObject



387
388
389
# File 'lib/pact_broker/pacts/selector.rb', line 387

def environment
  self[:environment]
end

#production_comparison(other) ⇒ Object



421
422
423
424
425
426
427
# File 'lib/pact_broker/pacts/selector.rb', line 421

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