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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -0
- data/lib/philiprehberger/pathname_kit/version.rb +1 -1
- data/lib/philiprehberger/pathname_kit.rb +19 -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: 76ddd3566c382deffcfaa116b8f24e6715f9b6a724301b3c0f1cfd8168abff7b
|
|
4
|
+
data.tar.gz: e373af1ca11000c3512a96a6c0e7f5c7a476dc7536fb2b595bb8deb1767321b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
|
@@ -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.
|
|
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-
|
|
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,
|