philiprehberger-pathname_kit 0.5.0 → 0.6.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: 022ccd8f2453dd90ab6292f5205556455f03bb4e2cca39e8257cd07cdfa0b0e4
4
- data.tar.gz: c187ad87694fb30b811f4aa63df279a1bec167bbc0ed13abfaa8d766b97bf17d
3
+ metadata.gz: 76ddd3566c382deffcfaa116b8f24e6715f9b6a724301b3c0f1cfd8168abff7b
4
+ data.tar.gz: e373af1ca11000c3512a96a6c0e7f5c7a476dc7536fb2b595bb8deb1767321b3
5
5
  SHA512:
6
- metadata.gz: 68aa6e2e50196068b4f317e8e9f55437ed796d0c021574f8c95f0bdd92b9afb7d573b9c02de444dfa0b72e11974450b084f2637f15c22797669e511f1c2a0e73
7
- data.tar.gz: faceb9ba3beebd59965beea08d5f7cc6afb1ec76c6f03ede7c30d41fdd25fb8b923442f2eca9995e4bb98d1b6602d11bb785c9db818492a94a4ecc67f121e28d
6
+ metadata.gz: e3c3f9a0c310b8cb644d0740b22b7242aca2b97f64dc6085026734ef762010c0d1c6a02e93450ffcaf1ca949c58c26416f6c2b600d2cfe16a3bf0dfc9b864880
7
+ data.tar.gz: 9233e060d7a9cfdd6754cad84bcdbf27e961eb82bdf3ada5f26f72b4aad937eecd8ce3502408f3b1181e6b9428a2c9910b342577476e46caa83ddd354e94c782
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-04-15
11
+
12
+ ### Added
13
+ - `relative_to(path, base)` for expressing a path relative to a base path
14
+
10
15
  ## [0.5.0] - 2026-04-14
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -140,6 +140,13 @@ Philiprehberger::PathnameKit.dirname("/path/to/file.txt") # => "/path/to"
140
140
  Philiprehberger::PathnameKit.mtime("config/app.yml") # => 2026-04-14 12:00:00 +0000
141
141
  ```
142
142
 
143
+ ### Relative Paths
144
+
145
+ ```ruby
146
+ Philiprehberger::PathnameKit.relative_to("/a/b/c.txt", "/a/b") # => "c.txt"
147
+ Philiprehberger::PathnameKit.relative_to("/a/foo", "/a/bar") # => "../foo"
148
+ ```
149
+
143
150
  ## API
144
151
 
145
152
  | Method | Description |
@@ -169,6 +176,7 @@ Philiprehberger::PathnameKit.mtime("config/app.yml") # => 2026-04-14 1
169
176
  | `.basename(path)` | Get the filename component of a path |
170
177
  | `.dirname(path)` | Get the directory component of a path |
171
178
  | `.mtime(path)` | Get the last modification time |
179
+ | `.relative_to(path, base)` | Express a path relative to a base path |
172
180
 
173
181
  ## Development
174
182
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module PathnameKit
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -320,6 +320,25 @@ module Philiprehberger
320
320
  File.expand_path(path.to_s)
321
321
  end
322
322
 
323
+ # Return +path+ expressed relative to +base+ as a String.
324
+ #
325
+ # Both arguments may be String or Pathname. Inputs are wrapped in
326
+ # Pathname and expanded so relative inputs are resolved against the
327
+ # current working directory before the relative path is computed.
328
+ #
329
+ # @param path [String, Pathname] the target path
330
+ # @param base [String, Pathname] the base path to compute relativity against
331
+ # @return [String] the relative path
332
+ # @raise [Error] if either argument is nil or empty
333
+ def self.relative_to(path, base)
334
+ raise Error, 'path cannot be nil' if path.nil?
335
+ raise Error, 'path cannot be empty' if path.to_s.empty?
336
+ raise Error, 'base cannot be nil' if base.nil?
337
+ raise Error, 'base cannot be empty' if base.to_s.empty?
338
+
339
+ Pathname.new(path.to_s).expand_path.relative_path_from(Pathname.new(base.to_s).expand_path).to_s
340
+ end
341
+
323
342
  # Check if a file or directory exists at the given path.
324
343
  #
325
344
  # @param path [String] the file or directory path
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-pathname_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-14 00:00:00.000000000 Z
11
+ date: 2026-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pathname utility library providing atomic writes, safe deletes, directory
14
14
  creation, glob-based file finding, tempfile helpers, copy, move, checksum, append,