summaryrefslogtreecommitdiff
path: root/dev-ruby/pathutil/files/pathutil-0.16.2-ruby30.patch
blob: 374cd400593051411f5502703247da46ab1ea0a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
From 3451a10c362fc867b20c7e471a551b31c40a0246 Mon Sep 17 00:00:00 2001
From: Tom Dunlap <tom@motevets.com>
Date: Tue, 9 Jun 2020 12:59:32 -0400
Subject: [PATCH] Fix ruby keyword parameter deprecation warnings

In ruby 2.7, using the last argument as keyword parameters became
deprecated in preparation for ruby 3.0. When running the tests, we saw
numerous deprecation warnings. This commit fixes up those deprecation
warnings by explicitly passing the last argument(s) as keyword
argument(s).

See: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

Fixes #4

Side note: this commit did not fix the `#binread` method because it was
untested, and when attempting to add tests, we got the following failing
test:

```
1) Pathutil#binread when set to normalize should use encode to convert CRLF to LF
   Failure/Error:
     File.binread(self, *args, kwd).encode({
       :universal_newline => true
     })

   TypeError:
     no implicit conversion of Hash into Integer
   # ./lib/pathutil.rb:509:in `binread'
   # ./lib/pathutil.rb:509:in `binread'
   # ./spec/tests/lib/pathutil_spec.rb:943:in `block (4 levels) in <top (required)>'
```

...which appears to be occuring because of an interface mismatch as
`IO#binread` does not take keyword arguments.

https://ruby-doc.org/core-2.7.1/IO.html#method-c-binread
---
 lib/pathutil.rb                         | 36 ++++++++-----------------
 spec/tests/lib/pathutil/helpers_spec.rb |  4 +--
 spec/tests/lib/pathutil_spec.rb         | 13 +++------
 3 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/lib/pathutil.rb b/lib/pathutil.rb
index 1a15873..80913f2 100644
--- a/lib/pathutil.rb
+++ b/lib/pathutil.rb
@@ -456,14 +456,10 @@ def safe_copy(to, root: nil, ignore: [])
     to   = self.class.new(to)
 
     if directory?
-      safe_copy_directory(to, {
-        :root => root, :ignore => ignore
-      })
+      safe_copy_directory(to, root: root, ignore: ignore)
 
     else
-      safe_copy_file(to, {
-        :root => root
-      })
+      safe_copy_file(to, root: root)
     end
   end
 
@@ -494,14 +490,10 @@ def read(*args, **kwd)
     kwd[:encoding] ||= encoding
 
     if normalize[:read]
-      File.read(self, *args, kwd).encode({
-        :universal_newline => true
-      })
+      File.read(self, *args, **kwd).encode(universal_newline: true)
 
     else
-      File.read(
-        self, *args, kwd
-      )
+      File.read(self, *args, **kwd)
     end
   end
 
@@ -534,13 +526,13 @@ def readlines(*args, **kwd)
     kwd[:encoding] ||= encoding
 
     if normalize[:read]
-      File.readlines(self, *args, kwd).encode({
+      File.readlines(self, *args, **kwd).encode({
         :universal_newline => true
       })
 
     else
       File.readlines(
-        self, *args, kwd
+        self, *args, **kwd
       )
     end
   end
@@ -556,11 +548,11 @@ def write(data, *args, **kwd)
     if normalize[:write]
       File.write(self, data.encode(
         :crlf_newline => true
-      ), *args, kwd)
+      ), *args, **kwd)
 
     else
       File.write(
-        self, data, *args, kwd
+        self, data, *args, **kwd
       )
     end
   end
@@ -670,9 +662,7 @@ def expanded_paths(path)
   private
   def safe_copy_file(to, root: nil)
     raise Errno::EPERM, "#{self} not in #{root}" unless in_path?(root)
-    FileUtils.cp(self, to, {
-      :preserve => true
-    })
+    FileUtils.cp(self, to, preserve: true)
   end
 
   # --
@@ -697,15 +687,11 @@ def safe_copy_directory(to, root: nil, ignore: [])
             }"
 
           elsif file.file?
-            FileUtils.cp(file, to, {
-              :preserve => true
-            })
+            FileUtils.cp(file, to, preserve: true)
 
           else
             path = file.realpath
-            path.safe_copy(to.join(file.basename), {
-              :root => root, :ignore => ignore
-            })
+            path.safe_copy(to.join(file.basename), root: root, ignore: ignore)
           end
         end
       end
diff --git a/spec/tests/lib/pathutil/helpers_spec.rb b/spec/tests/lib/pathutil/helpers_spec.rb
index 4d64d0a..0dfbc00 100644
--- a/spec/tests/lib/pathutil/helpers_spec.rb
+++ b/spec/tests/lib/pathutil/helpers_spec.rb
@@ -76,9 +76,7 @@
           #
 
           after do
-            described_class.load_yaml("hello: world", {
-              :aliases => true
-            })
+            described_class.load_yaml("hello: world", aliases: true)
           end
         end
 
diff --git a/spec/tests/lib/pathutil_spec.rb b/spec/tests/lib/pathutil_spec.rb
index 784a16b..0ee7a12 100644
--- a/spec/tests/lib/pathutil_spec.rb
+++ b/spec/tests/lib/pathutil_spec.rb
@@ -944,9 +944,7 @@
 
     context "with an encoding argument" do
       before do
-        file.write("hello", {
-          :encoding => "ASCII"
-        })
+        file.write("hello", encoding: "ASCII")
       end
 
       #
@@ -1050,11 +1048,10 @@
           name1.join(name2.basename, name1.basename).touch
           name1.join(name1.basename).touch
 
-          name1.safe_copy(name2, {
-            :root => tmpdir1, :ignore => [
+          name1.safe_copy(name2, root: tmpdir1, ignore: [
               name1.join(name2.basename, name1.basename)
             ]
-          })
+          )
         end
 
         #
@@ -1077,9 +1074,7 @@
           name1.join(name2.basename, name1.basename).touch
           name1.join(name1.basename).touch
 
-          name1.safe_copy(name2, {
-            :root => tmpdir1
-          })
+          name1.safe_copy(name2, root: tmpdir1)
         end
 
         #