Class: PactBroker::Domain::OrderVersions::OrderableVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/domain/order_versions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_model) ⇒ OrderableVersion

Returns a new instance of OrderableVersion.



63
64
65
66
# File 'lib/pact_broker/domain/order_versions.rb', line 63

def initialize version_model
  @version_model = version_model
  @sortable_number = PactBroker.configuration.version_parser.call version_model.number
end

Instance Attribute Details

#sortable_numberObject

Returns the value of attribute sortable_number.



61
62
63
# File 'lib/pact_broker/domain/order_versions.rb', line 61

def sortable_number
  @sortable_number
end

#version_modelObject

Returns the value of attribute version_model.



61
62
63
# File 'lib/pact_broker/domain/order_versions.rb', line 61

def version_model
  @version_model
end

Instance Method Details

#<=>(other) ⇒ Object

Incoming version numbers are rejected if they can’t be parsed by the version parser, however, the change from Versionomy to SemVer for version parsing means that some existing version numbers cannot be parsed and are returning nil. The main reason to sort the versions is to that we can get the “latest” pact. Any existing version with a number that cannot be parsed will almost definitely not be the “latest”, so sort them first.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pact_broker/domain/order_versions.rb', line 74

def <=> other
  if sortable_number.nil? && other.sortable_number.nil?
    0
  elsif sortable_number.nil?
    -1
  elsif other.sortable_number.nil?
    1
  else
    self.sortable_number <=> other.sortable_number
  end
end

#after?(other) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/pact_broker/domain/order_versions.rb', line 86

def after? other
  (self <=> other) == 1
end