pathname 0.1.0 → 0.2.1
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/.git-blame-ignore-revs +7 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +9 -6
- data/.gitignore +3 -0
- data/Gemfile +1 -0
- data/README.md +32 -6
- data/Rakefile +8 -0
- data/ext/pathname/pathname.c +26 -4
- data/{ext/pathname/lib → lib}/pathname.rb +11 -6
- data/pathname.gemspec +3 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222ab05e8698152edf5c4d2db5215d1385281d77e408234a03e9417d8f7e33c6
|
4
|
+
data.tar.gz: f267783875853911d60d63e08d7e871ba4562a84a73a335d1b72b453c3665a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b2b4a31d31f5e5dc9fe356c6a25a5a8f40b573604c073b9090ec53c09bafac5aafa61339b1396136659ef0ddeb1932955eb4e43f2ab7d83a906509a9412b313
|
7
|
+
data.tar.gz: 789a9cd9d5929793cabecde7d8a023ce153d1b5c11ef85da85aa8e0a74a427c85162c7cc0d09e85c3f33e8ee2f2d43bfeabed665fdd5f2742dec3611662204dd
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This is a file used by GitHub to ignore the following commits on `git blame`.
|
2
|
+
#
|
3
|
+
# You can also do the same thing in your local repository with:
|
4
|
+
# $ git config --local blame.ignoreRevsFile .git-blame-ignore-revs
|
5
|
+
|
6
|
+
# Expand tabs
|
7
|
+
93e8aaadc7c7945895b1b0b6d9909134409517ff
|
data/.github/workflows/test.yml
CHANGED
@@ -7,18 +7,21 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ 2.7,
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
10
|
+
ruby: [ 2.7, '3.0', 3.1, head ]
|
11
|
+
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
12
|
+
exclude:
|
13
|
+
- { os: windows-latest , ruby: head }
|
14
|
+
include:
|
15
|
+
- { os: windows-latest , ruby: mingw }
|
16
|
+
- { os: windows-latest , ruby: mswin }
|
12
17
|
runs-on: ${{ matrix.os }}
|
13
18
|
steps:
|
14
|
-
- uses: actions/checkout@
|
19
|
+
- uses: actions/checkout@v3
|
15
20
|
- name: Set up Ruby
|
16
21
|
uses: ruby/setup-ruby@v1
|
17
22
|
with:
|
18
23
|
ruby-version: ${{ matrix.ruby }}
|
19
24
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
25
|
+
run: bundle install
|
23
26
|
- name: Run test
|
24
27
|
run: rake compile test
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
# Pathname
|
2
2
|
|
3
|
-
|
3
|
+
Pathname represents the name of a file or directory on the filesystem,
|
4
|
+
but not the file itself.
|
4
5
|
|
5
|
-
|
6
|
+
The pathname depends on the Operating System: Unix, Windows, etc.
|
7
|
+
This library works with pathnames of local OS, however non-Unix pathnames
|
8
|
+
are supported experimentally.
|
9
|
+
|
10
|
+
A Pathname can be relative or absolute. It's not until you try to
|
11
|
+
reference the file that it even matters whether the file exists or not.
|
12
|
+
|
13
|
+
Pathname is immutable. It has no method for destructive update.
|
14
|
+
|
15
|
+
The goal of this class is to manipulate file path information in a neater
|
16
|
+
way than standard Ruby provides. The examples below demonstrate the
|
17
|
+
difference.
|
18
|
+
|
19
|
+
*All* functionality from File, FileTest, and some from Dir and FileUtils is
|
20
|
+
included, in an unsurprising way. It is essentially a facade for all of
|
21
|
+
these, and more.
|
6
22
|
|
7
23
|
## Installation
|
8
24
|
|
@@ -22,15 +38,25 @@ Or install it yourself as:
|
|
22
38
|
|
23
39
|
## Usage
|
24
40
|
|
25
|
-
|
41
|
+
```ruby
|
42
|
+
require 'pathname'
|
43
|
+
pn = Pathname.new("/usr/bin/ruby")
|
44
|
+
size = pn.size # 27662
|
45
|
+
isdir = pn.directory? # false
|
46
|
+
dir = pn.dirname # Pathname:/usr/bin
|
47
|
+
base = pn.basename # Pathname:ruby
|
48
|
+
dir, base = pn.split # [Pathname:/usr/bin, Pathname:ruby]
|
49
|
+
data = pn.read
|
50
|
+
pn.open { |f| _ }
|
51
|
+
pn.each_line { |line| _ }
|
52
|
+
```
|
26
53
|
|
27
54
|
## Development
|
28
55
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to compile this and run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
57
|
|
31
58
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
59
|
|
33
60
|
## Contributing
|
34
61
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/pathname.
|
data/Rakefile
CHANGED
@@ -3,9 +3,17 @@ require "rake/testtask"
|
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
5
|
t.libs << "test/lib"
|
6
|
+
t.ruby_opts << "-rhelper"
|
6
7
|
t.test_files = FileList["test/**/test_*.rb"]
|
7
8
|
end
|
8
9
|
|
10
|
+
task :sync_tool do
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
|
+
end
|
16
|
+
|
9
17
|
require 'rake/extensiontask'
|
10
18
|
Rake::ExtensionTask.new("pathname")
|
11
19
|
|
data/ext/pathname/pathname.c
CHANGED
@@ -35,6 +35,7 @@ static ID id_lchmod;
|
|
35
35
|
static ID id_lchown;
|
36
36
|
static ID id_link;
|
37
37
|
static ID id_lstat;
|
38
|
+
static ID id_lutime;
|
38
39
|
static ID id_mkdir;
|
39
40
|
static ID id_mtime;
|
40
41
|
static ID id_open;
|
@@ -360,10 +361,10 @@ path_each_line(int argc, VALUE *argv, VALUE self)
|
|
360
361
|
args[0] = get_strpath(self);
|
361
362
|
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
|
362
363
|
if (rb_block_given_p()) {
|
363
|
-
return
|
364
|
+
return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
|
364
365
|
}
|
365
366
|
else {
|
366
|
-
return
|
367
|
+
return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
|
367
368
|
}
|
368
369
|
}
|
369
370
|
|
@@ -764,6 +765,19 @@ path_utime(VALUE self, VALUE atime, VALUE mtime)
|
|
764
765
|
return rb_funcall(rb_cFile, id_utime, 3, atime, mtime, get_strpath(self));
|
765
766
|
}
|
766
767
|
|
768
|
+
/*
|
769
|
+
* Update the access and modification times of the file.
|
770
|
+
*
|
771
|
+
* Same as Pathname#utime, but does not follow symbolic links.
|
772
|
+
*
|
773
|
+
* See File.lutime.
|
774
|
+
*/
|
775
|
+
static VALUE
|
776
|
+
path_lutime(VALUE self, VALUE atime, VALUE mtime)
|
777
|
+
{
|
778
|
+
return rb_funcall(rb_cFile, id_lutime, 3, atime, mtime, get_strpath(self));
|
779
|
+
}
|
780
|
+
|
767
781
|
/*
|
768
782
|
* Returns the last component of the path.
|
769
783
|
*
|
@@ -834,7 +848,7 @@ path_split(VALUE self)
|
|
834
848
|
VALUE str = get_strpath(self);
|
835
849
|
VALUE ary, dirname, basename;
|
836
850
|
ary = rb_funcall(rb_cFile, id_split, 1, str);
|
837
|
-
ary
|
851
|
+
Check_Type(ary, T_ARRAY);
|
838
852
|
dirname = rb_ary_entry(ary, 0);
|
839
853
|
basename = rb_ary_entry(ary, 1);
|
840
854
|
dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
|
@@ -1212,7 +1226,7 @@ path_entries(VALUE self)
|
|
1212
1226
|
ary = rb_funcall(rb_cDir, id_entries, 1, str);
|
1213
1227
|
ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
|
1214
1228
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
1215
|
-
|
1229
|
+
VALUE elt = RARRAY_AREF(ary, i);
|
1216
1230
|
elt = rb_class_new_instance(1, &elt, klass);
|
1217
1231
|
rb_ary_store(ary, i, elt);
|
1218
1232
|
}
|
@@ -1274,6 +1288,7 @@ static VALUE
|
|
1274
1288
|
path_each_entry(VALUE self)
|
1275
1289
|
{
|
1276
1290
|
VALUE args[1];
|
1291
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
1277
1292
|
|
1278
1293
|
args[0] = get_strpath(self);
|
1279
1294
|
return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self));
|
@@ -1464,6 +1479,7 @@ path_f_pathname(VALUE self, VALUE str)
|
|
1464
1479
|
* - #make_symlink(old)
|
1465
1480
|
* - #truncate(length)
|
1466
1481
|
* - #utime(atime, mtime)
|
1482
|
+
* - #lutime(atime, mtime)
|
1467
1483
|
* - #basename(*args)
|
1468
1484
|
* - #dirname
|
1469
1485
|
* - #extname
|
@@ -1512,6 +1528,10 @@ path_f_pathname(VALUE self, VALUE str)
|
|
1512
1528
|
void
|
1513
1529
|
Init_pathname(void)
|
1514
1530
|
{
|
1531
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1532
|
+
rb_ext_ractor_safe(true);
|
1533
|
+
#endif
|
1534
|
+
|
1515
1535
|
InitVM(pathname);
|
1516
1536
|
|
1517
1537
|
rb_cPathname = rb_define_class("Pathname", rb_cObject);
|
@@ -1558,6 +1578,7 @@ Init_pathname(void)
|
|
1558
1578
|
rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
|
1559
1579
|
rb_define_method(rb_cPathname, "truncate", path_truncate, 1);
|
1560
1580
|
rb_define_method(rb_cPathname, "utime", path_utime, 2);
|
1581
|
+
rb_define_method(rb_cPathname, "lutime", path_lutime, 2);
|
1561
1582
|
rb_define_method(rb_cPathname, "basename", path_basename, -1);
|
1562
1583
|
rb_define_method(rb_cPathname, "dirname", path_dirname, 0);
|
1563
1584
|
rb_define_method(rb_cPathname, "extname", path_extname, 0);
|
@@ -1641,6 +1662,7 @@ InitVM_pathname(void)
|
|
1641
1662
|
id_lchown = rb_intern("lchown");
|
1642
1663
|
id_link = rb_intern("link");
|
1643
1664
|
id_lstat = rb_intern("lstat");
|
1665
|
+
id_lutime = rb_intern("lutime");
|
1644
1666
|
id_mkdir = rb_intern("mkdir");
|
1645
1667
|
id_mtime = rb_intern("mtime");
|
1646
1668
|
id_open = rb_intern("open");
|
@@ -338,6 +338,8 @@ class Pathname
|
|
338
338
|
|
339
339
|
#
|
340
340
|
# Appends a pathname fragment to +self+ to produce a new Pathname object.
|
341
|
+
# Since +other+ is considered as a path relative to +self+, if +other+ is
|
342
|
+
# an absolute path, the new Pathname object is created from just +other+.
|
341
343
|
#
|
342
344
|
# p1 = Pathname.new("/usr") # Pathname:/usr
|
343
345
|
# p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby
|
@@ -399,6 +401,8 @@ class Pathname
|
|
399
401
|
|
400
402
|
#
|
401
403
|
# Joins the given pathnames onto +self+ to create a new Pathname object.
|
404
|
+
# This is effectively the same as using Pathname#+ to append +self+ and
|
405
|
+
# all arguments sequentially.
|
402
406
|
#
|
403
407
|
# path0 = Pathname.new("/usr") # Pathname:/usr
|
404
408
|
# path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby
|
@@ -574,25 +578,26 @@ class Pathname # * Find *
|
|
574
578
|
end
|
575
579
|
|
576
580
|
|
581
|
+
autoload(:FileUtils, 'fileutils')
|
582
|
+
|
577
583
|
class Pathname # * FileUtils *
|
578
584
|
# Creates a full path, including any intermediate directories that don't yet
|
579
585
|
# exist.
|
580
586
|
#
|
581
587
|
# See FileUtils.mkpath and FileUtils.mkdir_p
|
582
|
-
def mkpath
|
583
|
-
|
584
|
-
FileUtils.mkpath(@path)
|
588
|
+
def mkpath(mode: nil)
|
589
|
+
FileUtils.mkpath(@path, mode: mode)
|
585
590
|
nil
|
586
591
|
end
|
587
592
|
|
588
593
|
# Recursively deletes a directory, including all directories beneath it.
|
589
594
|
#
|
590
|
-
# See FileUtils.
|
591
|
-
def rmtree
|
595
|
+
# See FileUtils.rm_rf
|
596
|
+
def rmtree(noop: nil, verbose: nil, secure: nil)
|
592
597
|
# The name "rmtree" is borrowed from File::Path of Perl.
|
593
598
|
# File::Path provides "mkpath" and "rmtree".
|
594
599
|
require 'fileutils'
|
595
|
-
FileUtils.
|
600
|
+
FileUtils.rm_rf(@path, noop: noop, verbose: verbose, secure: secure)
|
596
601
|
nil
|
597
602
|
end
|
598
603
|
end
|
data/pathname.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "pathname"
|
3
|
-
spec.version = "0.1
|
3
|
+
spec.version = "0.2.1"
|
4
4
|
spec.authors = ["Tanaka Akira"]
|
5
5
|
spec.email = ["akr@fsij.org"]
|
6
6
|
|
7
7
|
spec.summary = %q{Representation of the name of a file or directory on the filesystem}
|
8
8
|
spec.description = %q{Representation of the name of a file or directory on the filesystem}
|
9
9
|
spec.homepage = "https://github.com/ruby/pathname"
|
10
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
11
11
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
12
12
|
|
13
13
|
spec.metadata["homepage_uri"] = spec.homepage
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
20
|
end
|
21
21
|
spec.bindir = "exe"
|
22
|
-
spec.executables =
|
22
|
+
spec.executables = []
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
spec.extensions = %w[ext/pathname/extconf.rb]
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathname
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanaka Akira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Representation of the name of a file or directory on the filesystem
|
14
14
|
email:
|
@@ -18,6 +18,8 @@ extensions:
|
|
18
18
|
- ext/pathname/extconf.rb
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- ".git-blame-ignore-revs"
|
22
|
+
- ".github/dependabot.yml"
|
21
23
|
- ".github/workflows/test.yml"
|
22
24
|
- ".gitignore"
|
23
25
|
- Gemfile
|
@@ -27,8 +29,8 @@ files:
|
|
27
29
|
- bin/console
|
28
30
|
- bin/setup
|
29
31
|
- ext/pathname/extconf.rb
|
30
|
-
- ext/pathname/lib/pathname.rb
|
31
32
|
- ext/pathname/pathname.c
|
33
|
+
- lib/pathname.rb
|
32
34
|
- pathname.gemspec
|
33
35
|
homepage: https://github.com/ruby/pathname
|
34
36
|
licenses:
|
@@ -45,14 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
47
|
requirements:
|
46
48
|
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
50
|
+
version: 2.7.0
|
49
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
52
|
requirements:
|
51
53
|
- - ">="
|
52
54
|
- !ruby/object:Gem::Version
|
53
55
|
version: '0'
|
54
56
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.4.0.dev
|
56
58
|
signing_key:
|
57
59
|
specification_version: 4
|
58
60
|
summary: Representation of the name of a file or directory on the filesystem
|