philiprehberger-pathname_kit 0.4.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 +14 -0
- data/README.md +23 -0
- data/lib/philiprehberger/pathname_kit/version.rb +1 -1
- data/lib/philiprehberger/pathname_kit.rb +80 -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,20 @@ 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
|
+
|
|
15
|
+
## [0.5.0] - 2026-04-14
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `exists?(path)` for checking if a file or directory exists
|
|
19
|
+
- `directory?(path)` for checking if a path is a directory
|
|
20
|
+
- `basename(path)` for getting the filename component of a path
|
|
21
|
+
- `dirname(path)` for getting the directory component of a path
|
|
22
|
+
- `mtime(path)` for getting the last modification time
|
|
23
|
+
|
|
10
24
|
## [0.4.0] - 2026-04-10
|
|
11
25
|
|
|
12
26
|
### Added
|
data/README.md
CHANGED
|
@@ -130,6 +130,23 @@ Philiprehberger::PathnameKit.extension("archive.tar.gz") # => ".gz"
|
|
|
130
130
|
Philiprehberger::PathnameKit.expand("~/docs/notes.md") # => "/home/user/docs/notes.md"
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
### Path Queries
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
Philiprehberger::PathnameKit.exists?("config/app.yml") # => true or false
|
|
137
|
+
Philiprehberger::PathnameKit.directory?("config") # => true or false
|
|
138
|
+
Philiprehberger::PathnameKit.basename("/path/to/file.txt") # => "file.txt"
|
|
139
|
+
Philiprehberger::PathnameKit.dirname("/path/to/file.txt") # => "/path/to"
|
|
140
|
+
Philiprehberger::PathnameKit.mtime("config/app.yml") # => 2026-04-14 12:00:00 +0000
|
|
141
|
+
```
|
|
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
|
+
|
|
133
150
|
## API
|
|
134
151
|
|
|
135
152
|
| Method | Description |
|
|
@@ -154,6 +171,12 @@ Philiprehberger::PathnameKit.expand("~/docs/notes.md") # => "/home/user/docs/
|
|
|
154
171
|
| `.empty?(path)` | Check if a file is zero bytes |
|
|
155
172
|
| `.extension(path)` | Get the file extension (e.g. `".rb"`) |
|
|
156
173
|
| `.expand(path)` | Expand to absolute path with tilde expansion |
|
|
174
|
+
| `.exists?(path)` | Check if a file or directory exists |
|
|
175
|
+
| `.directory?(path)` | Check if a path is a directory |
|
|
176
|
+
| `.basename(path)` | Get the filename component of a path |
|
|
177
|
+
| `.dirname(path)` | Get the directory component of a path |
|
|
178
|
+
| `.mtime(path)` | Get the last modification time |
|
|
179
|
+
| `.relative_to(path, base)` | Express a path relative to a base path |
|
|
157
180
|
|
|
158
181
|
## Development
|
|
159
182
|
|
|
@@ -319,5 +319,85 @@ module Philiprehberger
|
|
|
319
319
|
|
|
320
320
|
File.expand_path(path.to_s)
|
|
321
321
|
end
|
|
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
|
+
|
|
342
|
+
# Check if a file or directory exists at the given path.
|
|
343
|
+
#
|
|
344
|
+
# @param path [String] the file or directory path
|
|
345
|
+
# @return [Boolean] true if the path exists
|
|
346
|
+
# @raise [Error] if path is nil or empty
|
|
347
|
+
def self.exists?(path)
|
|
348
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
349
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
350
|
+
|
|
351
|
+
File.exist?(path.to_s)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Check if the given path is a directory.
|
|
355
|
+
#
|
|
356
|
+
# @param path [String] the path to check
|
|
357
|
+
# @return [Boolean] true if the path is a directory
|
|
358
|
+
# @raise [Error] if path is nil or empty
|
|
359
|
+
def self.directory?(path)
|
|
360
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
361
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
362
|
+
|
|
363
|
+
File.directory?(path.to_s)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# Get the filename component of a path (without directory).
|
|
367
|
+
#
|
|
368
|
+
# @param path [String] the file path
|
|
369
|
+
# @return [String] the filename
|
|
370
|
+
# @raise [Error] if path is nil or empty
|
|
371
|
+
def self.basename(path)
|
|
372
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
373
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
374
|
+
|
|
375
|
+
File.basename(path.to_s)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# Get the directory component of a path.
|
|
379
|
+
#
|
|
380
|
+
# @param path [String] the file path
|
|
381
|
+
# @return [String] the directory portion
|
|
382
|
+
# @raise [Error] if path is nil or empty
|
|
383
|
+
def self.dirname(path)
|
|
384
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
385
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
386
|
+
|
|
387
|
+
File.dirname(path.to_s)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
# Get the last modification time of a file or directory.
|
|
391
|
+
#
|
|
392
|
+
# @param path [String] the file or directory path
|
|
393
|
+
# @return [Time] the modification time
|
|
394
|
+
# @raise [Error] if path is nil/empty or does not exist
|
|
395
|
+
def self.mtime(path)
|
|
396
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
397
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
398
|
+
raise Error, "path not found: #{path}" unless File.exist?(path.to_s)
|
|
399
|
+
|
|
400
|
+
File.mtime(path.to_s)
|
|
401
|
+
end
|
|
322
402
|
end
|
|
323
403
|
end
|
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,
|