philiprehberger-pathname_kit 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 +9 -0
- data/README.md +15 -0
- data/lib/philiprehberger/pathname_kit/version.rb +1 -1
- data/lib/philiprehberger/pathname_kit.rb +61 -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: 022ccd8f2453dd90ab6292f5205556455f03bb4e2cca39e8257cd07cdfa0b0e4
|
|
4
|
+
data.tar.gz: c187ad87694fb30b811f4aa63df279a1bec167bbc0ed13abfaa8d766b97bf17d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68aa6e2e50196068b4f317e8e9f55437ed796d0c021574f8c95f0bdd92b9afb7d573b9c02de444dfa0b72e11974450b084f2637f15c22797669e511f1c2a0e73
|
|
7
|
+
data.tar.gz: faceb9ba3beebd59965beea08d5f7cc6afb1ec76c6f03ede7c30d41fdd25fb8b923442f2eca9995e4bb98d1b6602d11bb785c9db818492a94a4ecc67f121e28d
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ 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-04-14
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `exists?(path)` for checking if a file or directory exists
|
|
14
|
+
- `directory?(path)` for checking if a path is a directory
|
|
15
|
+
- `basename(path)` for getting the filename component of a path
|
|
16
|
+
- `dirname(path)` for getting the directory component of a path
|
|
17
|
+
- `mtime(path)` for getting the last modification time
|
|
18
|
+
|
|
10
19
|
## [0.4.0] - 2026-04-10
|
|
11
20
|
|
|
12
21
|
### Added
|
data/README.md
CHANGED
|
@@ -130,6 +130,16 @@ 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
|
+
|
|
133
143
|
## API
|
|
134
144
|
|
|
135
145
|
| Method | Description |
|
|
@@ -154,6 +164,11 @@ Philiprehberger::PathnameKit.expand("~/docs/notes.md") # => "/home/user/docs/
|
|
|
154
164
|
| `.empty?(path)` | Check if a file is zero bytes |
|
|
155
165
|
| `.extension(path)` | Get the file extension (e.g. `".rb"`) |
|
|
156
166
|
| `.expand(path)` | Expand to absolute path with tilde expansion |
|
|
167
|
+
| `.exists?(path)` | Check if a file or directory exists |
|
|
168
|
+
| `.directory?(path)` | Check if a path is a directory |
|
|
169
|
+
| `.basename(path)` | Get the filename component of a path |
|
|
170
|
+
| `.dirname(path)` | Get the directory component of a path |
|
|
171
|
+
| `.mtime(path)` | Get the last modification time |
|
|
157
172
|
|
|
158
173
|
## Development
|
|
159
174
|
|
|
@@ -319,5 +319,66 @@ module Philiprehberger
|
|
|
319
319
|
|
|
320
320
|
File.expand_path(path.to_s)
|
|
321
321
|
end
|
|
322
|
+
|
|
323
|
+
# Check if a file or directory exists at the given path.
|
|
324
|
+
#
|
|
325
|
+
# @param path [String] the file or directory path
|
|
326
|
+
# @return [Boolean] true if the path exists
|
|
327
|
+
# @raise [Error] if path is nil or empty
|
|
328
|
+
def self.exists?(path)
|
|
329
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
330
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
331
|
+
|
|
332
|
+
File.exist?(path.to_s)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Check if the given path is a directory.
|
|
336
|
+
#
|
|
337
|
+
# @param path [String] the path to check
|
|
338
|
+
# @return [Boolean] true if the path is a directory
|
|
339
|
+
# @raise [Error] if path is nil or empty
|
|
340
|
+
def self.directory?(path)
|
|
341
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
342
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
343
|
+
|
|
344
|
+
File.directory?(path.to_s)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# Get the filename component of a path (without directory).
|
|
348
|
+
#
|
|
349
|
+
# @param path [String] the file path
|
|
350
|
+
# @return [String] the filename
|
|
351
|
+
# @raise [Error] if path is nil or empty
|
|
352
|
+
def self.basename(path)
|
|
353
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
354
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
355
|
+
|
|
356
|
+
File.basename(path.to_s)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Get the directory component of a path.
|
|
360
|
+
#
|
|
361
|
+
# @param path [String] the file path
|
|
362
|
+
# @return [String] the directory portion
|
|
363
|
+
# @raise [Error] if path is nil or empty
|
|
364
|
+
def self.dirname(path)
|
|
365
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
366
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
367
|
+
|
|
368
|
+
File.dirname(path.to_s)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# Get the last modification time of a file or directory.
|
|
372
|
+
#
|
|
373
|
+
# @param path [String] the file or directory path
|
|
374
|
+
# @return [Time] the modification time
|
|
375
|
+
# @raise [Error] if path is nil/empty or does not exist
|
|
376
|
+
def self.mtime(path)
|
|
377
|
+
raise Error, 'path cannot be nil' if path.nil?
|
|
378
|
+
raise Error, 'path cannot be empty' if path.to_s.empty?
|
|
379
|
+
raise Error, "path not found: #{path}" unless File.exist?(path.to_s)
|
|
380
|
+
|
|
381
|
+
File.mtime(path.to_s)
|
|
382
|
+
end
|
|
322
383
|
end
|
|
323
384
|
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.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-
|
|
11
|
+
date: 2026-04-14 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,
|