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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a91bc47b98cf1f9c5e98b0318859928eb5b5b643f7e11731ed261dd8f6a36748
4
- data.tar.gz: 0cf92cd231bcd7e9ecb5c11daf634ba49738ee9caaa2a8a74ad78830fa4ded53
3
+ metadata.gz: 450510c518a2b1269153611f05c0c7646b54d987854e76ff09e160454fd3477c
4
+ data.tar.gz: e33e54ef7cec42703e60708e71a8912c9a3e233e267f77b0c21648abb92ac2ac
5
5
  SHA512:
6
- metadata.gz: 4f0fbf52e71a05e6aa26f689682690e0c97338cfa7a9efb3bfd79d99faaec7a6f6ca7dc67a73d4cecbb30a5708a1f0f12e15190bc320c30adb898ed2e6a8bb64
7
- data.tar.gz: 839070f4538e9185b3e5d696befccc8b8ad60d209be8b00883cb9e64fa6379f81943d1601b85f7e17bbc4adbc3fb521108eb3ce2305ebd3a0bfd18bcf32102c3
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
  [![Gem Version](https://badge.fury.io/rb/philiprehberger-version_compare.svg)](https://rubygems.org/gems/philiprehberger-version_compare)
5
5
  [![Last updated](https://img.shields.io/github/last-commit/philiprehberger/rb-version-compare)](https://github.com/philiprehberger/rb-version-compare/commits/main)
6
6
 
7
+ ![philiprehberger-version_compare](https://raw.githubusercontent.com/philiprehberger/rb-version-compare/main/package-card.webp)
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module VersionCompare
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -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.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-04-26 00:00:00.000000000 Z
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.