Class: PactBroker::Domain::OrderVersions::OrderableVersion
- Inherits:
-
Object
- Object
- PactBroker::Domain::OrderVersions::OrderableVersion
- Defined in:
- lib/pact_broker/domain/order_versions.rb
Instance Attribute Summary collapse
-
#sortable_number ⇒ Object
Returns the value of attribute sortable_number.
-
#version_model ⇒ Object
Returns the value of attribute version_model.
Instance Method Summary collapse
-
#<=>(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.
- #after?(other) ⇒ Boolean
-
#initialize(version_model) ⇒ OrderableVersion
constructor
A new instance of OrderableVersion.
Constructor Details
#initialize(version_model) ⇒ OrderableVersion
Returns a new instance of OrderableVersion.
50 51 52 53 |
# File 'lib/pact_broker/domain/order_versions.rb', line 50 def initialize version_model @version_model = version_model @sortable_number = PactBroker.configuration.version_parser.call version_model.number end |
Instance Attribute Details
#sortable_number ⇒ Object
Returns the value of attribute sortable_number.
48 49 50 |
# File 'lib/pact_broker/domain/order_versions.rb', line 48 def sortable_number @sortable_number end |
#version_model ⇒ Object
Returns the value of attribute version_model.
48 49 50 |
# File 'lib/pact_broker/domain/order_versions.rb', line 48 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.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pact_broker/domain/order_versions.rb', line 61 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
73 74 75 |
# File 'lib/pact_broker/domain/order_versions.rb', line 73 def after? other (self <=> other) == 1 end |