philiprehberger-version_compare 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +20 -0
- data/lib/philiprehberger/version_compare/version.rb +1 -1
- data/lib/philiprehberger/version_compare.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 450510c518a2b1269153611f05c0c7646b54d987854e76ff09e160454fd3477c
|
|
4
|
+
data.tar.gz: e33e54ef7cec42703e60708e71a8912c9a3e233e267f77b0c21648abb92ac2ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44780be3cc465e16143cf75e161301088e8ce2c11533673771b68b40e059651badb02ff43d81badeb9118c0fd33218497c7f86e28e1c0dc185b0c278471227bf
|
|
7
|
+
data.tar.gz: 650c55ec56bcec915f9118d414b3afecf523b24cfc33889c9cc4a292dca4b7b2c53af08fbd36475c520d56eb6a7d8f9b3ff389682f8579863340e73c4dc9898b
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-05-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `VersionCompare.compatible?(baseline, candidate)` — SemVer API-compatibility check: same major and candidate >= baseline (pre-1.0 also requires matching minor)
|
|
14
|
+
- Card image reference in the README for registry-side rendering
|
|
15
|
+
|
|
10
16
|
## [0.4.0] - 2026-04-25
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-version_compare)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-version-compare/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Version string parsing with comparison, sorting, and constraint matching
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -153,6 +155,23 @@ Philiprehberger::VersionCompare.highest_satisfying(versions, '>= 4.0.0')
|
|
|
153
155
|
# => nil
|
|
154
156
|
```
|
|
155
157
|
|
|
158
|
+
### API Compatibility Check
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
# Same major + candidate >= baseline => compatible
|
|
162
|
+
Philiprehberger::VersionCompare.compatible?("1.2.0", "1.5.3") # => true
|
|
163
|
+
|
|
164
|
+
# Different major => incompatible
|
|
165
|
+
Philiprehberger::VersionCompare.compatible?("1.5.0", "2.0.0") # => false
|
|
166
|
+
|
|
167
|
+
# Below baseline => incompatible
|
|
168
|
+
Philiprehberger::VersionCompare.compatible?("1.5.0", "1.4.9") # => false
|
|
169
|
+
|
|
170
|
+
# Pre-1.0.0 requires matching minor (matches `~>` semantics)
|
|
171
|
+
Philiprehberger::VersionCompare.compatible?("0.3.0", "0.3.4") # => true
|
|
172
|
+
Philiprehberger::VersionCompare.compatible?("0.3.0", "0.4.0") # => false
|
|
173
|
+
```
|
|
174
|
+
|
|
156
175
|
## API
|
|
157
176
|
|
|
158
177
|
### `Philiprehberger::VersionCompare`
|
|
@@ -165,6 +184,7 @@ Philiprehberger::VersionCompare.highest_satisfying(versions, '>= 4.0.0')
|
|
|
165
184
|
| `.filter(versions, constraint)` | Filter an array of version strings by a constraint |
|
|
166
185
|
| `.highest_satisfying(versions, constraint)` | Return the highest version string that satisfies a constraint, or `nil` |
|
|
167
186
|
| `.min(versions)` / `.max(versions)` | Lowest/highest version from a list |
|
|
187
|
+
| `.compatible?(baseline, candidate)` | API-compatibility check: same major + candidate >= baseline (pre-1.0 also requires matching minor) |
|
|
168
188
|
|
|
169
189
|
### `SemanticVersion`
|
|
170
190
|
|
|
@@ -225,6 +225,30 @@ module Philiprehberger
|
|
|
225
225
|
versions.select { |v| parse(v).satisfies?(constraint) }
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
+
# Check whether two versions are API-compatible per SemVer.
|
|
229
|
+
#
|
|
230
|
+
# Two versions are considered compatible when:
|
|
231
|
+
# - both share the same major component, AND
|
|
232
|
+
# - the candidate is greater than or equal to the baseline (so it has every API
|
|
233
|
+
# the baseline expects)
|
|
234
|
+
#
|
|
235
|
+
# When the baseline is pre-1.0.0 (major == 0), SemVer considers every minor bump
|
|
236
|
+
# potentially breaking; in that regime compatibility additionally requires the
|
|
237
|
+
# same minor component, matching the `~>` (pessimistic) constraint behavior.
|
|
238
|
+
#
|
|
239
|
+
# @param baseline [String, SemanticVersion] the version your code expects
|
|
240
|
+
# @param candidate [String, SemanticVersion] the version actually present
|
|
241
|
+
# @return [Boolean] true when `candidate` is API-compatible with `baseline`
|
|
242
|
+
def self.compatible?(baseline, candidate)
|
|
243
|
+
base = baseline.is_a?(SemanticVersion) ? baseline : parse(baseline)
|
|
244
|
+
cand = candidate.is_a?(SemanticVersion) ? candidate : parse(candidate)
|
|
245
|
+
|
|
246
|
+
return false unless base.major == cand.major
|
|
247
|
+
return false if cand < base
|
|
248
|
+
|
|
249
|
+
base.major.zero? ? base.minor == cand.minor : true
|
|
250
|
+
end
|
|
251
|
+
|
|
228
252
|
# Return the highest version from an array that satisfies a constraint
|
|
229
253
|
#
|
|
230
254
|
# Performs a single pass over versions, tracking the maximum parsed
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-version_compare
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Parse semantic version strings into comparable objects with support for
|
|
14
14
|
sorting, finding the latest version, and checking constraint satisfaction.
|