pathutil 0.4.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Rakefile +7 -7
- data/lib/pathutil.rb +77 -114
- data/lib/pathutil/helpers.rb +6 -1
- data/lib/pathutil/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0379be022c3075e3a84b161087c637460dadf4d
|
4
|
+
data.tar.gz: 835f3036a786ac0096522886b66f11d9b5584e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2e6321fbcbb23807bc9de1a166c20a3566d481c39240ae48aa6d898834f8d17aeefd206e624061ea0a2d514ad3b688374b9b566c4c348b1dfa9f5a67384c6c0
|
7
|
+
data.tar.gz: be5897bdcdf38edf0494f4dadb9963345c33cb40aa10f73807861702d593660afa74b7352169695ec6e68e6ecf3ee4bee6aedef674524fca80bc33c12a55eef8
|
data/Gemfile
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
3
|
# Copyright: 2015-2016 Jordon Bedwell - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
source "https://rubygems.org"
|
6
8
|
gem "rake", :require => false
|
7
9
|
gemspec
|
8
10
|
|
9
11
|
group :test do
|
12
|
+
gem "luna-rspec-formatters", :require => false
|
10
13
|
gem "codeclimate-test-reporter", :require => false
|
11
14
|
gem "safe_yaml", :require => false
|
12
15
|
end
|
@@ -16,7 +19,6 @@ group :development do
|
|
16
19
|
gem "rspec-helpers", :require => false
|
17
20
|
gem "luna-rubocop-formatters", :require => false
|
18
21
|
gem "rubocop", :github => "bbatsov/rubocop", :require => false
|
19
|
-
gem "luna-rspec-formatters", :require => false
|
20
22
|
gem "benchmark-ips", :require => false
|
21
23
|
gem "simple-ansi", :require => false
|
22
24
|
gem "pry", :require => false
|
data/Rakefile
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
3
|
# Copyright: 2015-2016 Jordon Bedwell - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
require "open3"
|
6
8
|
require "rspec/core/rake_task"
|
7
9
|
require_relative "benchmark/support/task"
|
10
|
+
require "luna/rubocop/rake/task"
|
8
11
|
require "simple/ansi"
|
9
12
|
require "pathutil"
|
10
13
|
require "json"
|
11
14
|
|
15
|
+
# ----------------------------------------------------------------------------
|
16
|
+
|
12
17
|
task :default => [
|
13
18
|
ENV["BENCHMARK"] ? :benchmark : :spec
|
14
19
|
]
|
15
20
|
|
21
|
+
# ----------------------------------------------------------------------------
|
22
|
+
|
16
23
|
BenchmarkTask.new :benchmark
|
17
24
|
RSpec::Core::RakeTask.new :spec
|
18
25
|
task :test => :spec
|
@@ -74,10 +81,3 @@ task :methods do
|
|
74
81
|
|
75
82
|
$stdout.puts
|
76
83
|
end
|
77
|
-
|
78
|
-
# ----------------------------------------------------------------------------
|
79
|
-
|
80
|
-
task :rubocop do
|
81
|
-
sh "bundle", "exec", "rubocop", "-DE", "-r", "luna/rubocop/formatters/checks", \
|
82
|
-
"-f", "Luna::RuboCop::Formatters::Checks"
|
83
|
-
end
|
data/lib/pathutil.rb
CHANGED
@@ -8,13 +8,13 @@ require "pathutil/helpers"
|
|
8
8
|
require "forwardable/extended"
|
9
9
|
require "find"
|
10
10
|
|
11
|
-
#
|
12
|
-
|
13
11
|
class Pathutil
|
14
12
|
attr_writer :encoding
|
15
13
|
extend Forwardable::Extended
|
16
14
|
extend Helpers
|
17
15
|
|
16
|
+
# --------------------------------------------------------------------------
|
17
|
+
# Note: A lot of this class can be compatible with Pathname.
|
18
18
|
# --------------------------------------------------------------------------
|
19
19
|
|
20
20
|
def initialize(path)
|
@@ -24,15 +24,9 @@ class Pathutil
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# --------------------------------------------------------------------------
|
27
|
+
# Note: It will return all results that it finds across all ascending paths.
|
28
|
+
# Example: Pathutil.new("~/").expand_path.search_backwards(".bashrc") => [#<Pathutil:/home/user/.bashrc>]
|
27
29
|
# Search backwards for a file (like Rakefile, _config.yml, opts.yml).
|
28
|
-
# @note It will return all results that it finds across all ascending paths.
|
29
|
-
# @param backwards how far do you wish to search backwards in that path?
|
30
|
-
# @param file the file you are searching for.
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# Pathutil.new("~/").expand_path.search_backwards(".bashrc") => [
|
34
|
-
# #<Pathutil:/home/user/.bashrc>
|
35
|
-
# ]
|
36
30
|
# --------------------------------------------------------------------------
|
37
31
|
|
38
32
|
def search_backwards(file, backwards: Float::INFINITY)
|
@@ -64,6 +58,9 @@ class Pathutil
|
|
64
58
|
ary
|
65
59
|
end
|
66
60
|
|
61
|
+
# --------------------------------------------------------------------------
|
62
|
+
# See: self.class.load_yaml as this a direct alias of that method.
|
63
|
+
# Read the file as a YAML file turning it into an object.
|
67
64
|
# --------------------------------------------------------------------------
|
68
65
|
|
69
66
|
def read_yaml(throw_missing: false, **kwd)
|
@@ -77,6 +74,9 @@ class Pathutil
|
|
77
74
|
)
|
78
75
|
end
|
79
76
|
|
77
|
+
# --------------------------------------------------------------------------
|
78
|
+
# See: self.class.read_json as this is a direct alias of that method.
|
79
|
+
# Read the file as a JSON file turning it into an object.
|
80
80
|
# --------------------------------------------------------------------------
|
81
81
|
|
82
82
|
def read_json(throw_missing: false)
|
@@ -91,13 +91,9 @@ class Pathutil
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# --------------------------------------------------------------------------
|
94
|
+
# Note: The blank part is intentionally left there so that you can rejoin.
|
94
95
|
# Splits the path into all parts so that you can do step by step comparisons
|
95
|
-
#
|
96
|
-
#
|
97
|
-
# @example
|
98
|
-
# Pathutil.new("/my/path").split_path # => [
|
99
|
-
# "", "my", "path"
|
100
|
-
# ]
|
96
|
+
# Example: Pathutil.new("/my/path").split_path # => ["", "my", "path"]
|
101
97
|
# --------------------------------------------------------------------------
|
102
98
|
|
103
99
|
def split_path
|
@@ -107,10 +103,8 @@ class Pathutil
|
|
107
103
|
end
|
108
104
|
|
109
105
|
# --------------------------------------------------------------------------
|
110
|
-
# @see `String#==` for more details.
|
111
106
|
# A stricter version of `==` that also makes sure the object matches.
|
112
|
-
#
|
113
|
-
# @return true, false
|
107
|
+
# See: `String#==` for more details.
|
114
108
|
# --------------------------------------------------------------------------
|
115
109
|
|
116
110
|
def ===(other)
|
@@ -118,11 +112,9 @@ class Pathutil
|
|
118
112
|
end
|
119
113
|
|
120
114
|
# --------------------------------------------------------------------------
|
121
|
-
# @example Pathutil.new("/hello") >= Pathutil.new("/") # => true
|
122
|
-
# @example Pathutil.new("/hello") >= Pathutil.new("/hello") # => true
|
123
115
|
# Checks to see if a path falls within a path and deeper or is the other.
|
124
|
-
#
|
125
|
-
#
|
116
|
+
# Example: Pathutil.new("/hello") >= Pathutil.new("/hello") # => true
|
117
|
+
# Example: Pathutil.new("/hello") >= Pathutil.new("/") # => true
|
126
118
|
# --------------------------------------------------------------------------
|
127
119
|
|
128
120
|
def >=(other)
|
@@ -132,10 +124,8 @@ class Pathutil
|
|
132
124
|
end
|
133
125
|
|
134
126
|
# --------------------------------------------------------------------------
|
135
|
-
# @example Pathutil.new("/hello/world") > Pathutil.new("/hello") # => true
|
136
127
|
# Strictly checks to see if a path is deeper but within the path of the other.
|
137
|
-
#
|
138
|
-
# @return true, false
|
128
|
+
# Example: Pathutil.new("/hello/world") > Pathutil.new("/hello") # => true
|
139
129
|
# --------------------------------------------------------------------------
|
140
130
|
|
141
131
|
def >(other)
|
@@ -145,10 +135,8 @@ class Pathutil
|
|
145
135
|
end
|
146
136
|
|
147
137
|
# --------------------------------------------------------------------------
|
148
|
-
# @example Pathutil.new("/") < Pathutil.new("/hello") # => true
|
149
138
|
# Strictly check to see if a path is behind other path but within it.
|
150
|
-
#
|
151
|
-
# @return true, false
|
139
|
+
# Example: Pathutil.new("/") < Pathutil.new("/hello") # => true
|
152
140
|
# --------------------------------------------------------------------------
|
153
141
|
|
154
142
|
def <(other)
|
@@ -158,11 +146,9 @@ class Pathutil
|
|
158
146
|
end
|
159
147
|
|
160
148
|
# --------------------------------------------------------------------------
|
161
|
-
# Check to see if a path is behind the other path
|
162
|
-
#
|
163
|
-
#
|
164
|
-
# @param path the path that should be below the object.
|
165
|
-
# @return true, false
|
149
|
+
# Check to see if a path is behind the other path but within it.
|
150
|
+
# Example: Pathutil.new("/hello") < Pathutil.new("/hello") # => true
|
151
|
+
# Example: Pathutil.new("/") < Pathutil.new("/hello") # => true
|
166
152
|
# --------------------------------------------------------------------------
|
167
153
|
|
168
154
|
def <=(other)
|
@@ -172,9 +158,8 @@ class Pathutil
|
|
172
158
|
end
|
173
159
|
|
174
160
|
# --------------------------------------------------------------------------
|
175
|
-
# @note "./" is considered relative.
|
176
161
|
# Check to see if the path is absolute, as in: starts with "/"
|
177
|
-
#
|
162
|
+
# Note: "./" is considered relative.
|
178
163
|
# --------------------------------------------------------------------------
|
179
164
|
|
180
165
|
def absolute?
|
@@ -183,21 +168,8 @@ class Pathutil
|
|
183
168
|
|
184
169
|
# --------------------------------------------------------------------------
|
185
170
|
# Break apart the path and yield each with the previous parts.
|
186
|
-
#
|
187
|
-
#
|
188
|
-
# @example
|
189
|
-
# Pathutil.new("/hello/world").ascend.to_a # => [
|
190
|
-
# "/", "/hello", "/hello/world"
|
191
|
-
# ]
|
192
|
-
#
|
193
|
-
# @example
|
194
|
-
# Pathutil.new("/hello/world").ascend do |path|
|
195
|
-
# $stdout.puts path
|
196
|
-
# end
|
197
|
-
#
|
198
|
-
# /
|
199
|
-
# /hello
|
200
|
-
# /hello/world
|
171
|
+
# Example: Pathutil.new("/hello/world").ascend.to_a # => ["/", "/hello", "/hello/world"]
|
172
|
+
# Example: Pathutil.new("/hello/world").ascend { |path| $stdout.puts path }
|
201
173
|
# --------------------------------------------------------------------------
|
202
174
|
|
203
175
|
def ascend
|
@@ -225,21 +197,8 @@ class Pathutil
|
|
225
197
|
|
226
198
|
# --------------------------------------------------------------------------
|
227
199
|
# Break apart the path in reverse order and descend into the path.
|
228
|
-
#
|
229
|
-
#
|
230
|
-
# @example
|
231
|
-
# Pathutil.new("/hello/world").descend.to_a # => [
|
232
|
-
# "/hello/world", "/hello", "/"
|
233
|
-
# ]
|
234
|
-
#
|
235
|
-
# @example
|
236
|
-
# Pathutil.new("/hello/world").descend do |path|
|
237
|
-
# $stdout.puts path
|
238
|
-
# end
|
239
|
-
#
|
240
|
-
# /hello/world
|
241
|
-
# /hello
|
242
|
-
# /
|
200
|
+
# Example: Pathutil.new("/hello/world").descend.to_a # => ["/hello/world", "/hello", "/"]
|
201
|
+
# Example: Pathutil.new("/hello/world").descend { |path| $stdout.puts path }
|
243
202
|
# --------------------------------------------------------------------------
|
244
203
|
|
245
204
|
def descend
|
@@ -257,15 +216,8 @@ class Pathutil
|
|
257
216
|
end
|
258
217
|
|
259
218
|
# --------------------------------------------------------------------------
|
219
|
+
# Example: Pathutil.new("/hello/world").each_line { |line| $stdout.puts line }
|
260
220
|
# Wraps `readlines` and allows you to yield on the result.
|
261
|
-
#
|
262
|
-
# @example
|
263
|
-
# Pathutil.new("/hello/world").each_line do |line|
|
264
|
-
# $stdout.puts line
|
265
|
-
# end
|
266
|
-
#
|
267
|
-
# Hello
|
268
|
-
# World
|
269
221
|
# --------------------------------------------------------------------------
|
270
222
|
|
271
223
|
def each_line
|
@@ -278,12 +230,10 @@ class Pathutil
|
|
278
230
|
end
|
279
231
|
|
280
232
|
# --------------------------------------------------------------------------
|
281
|
-
#
|
233
|
+
# Example: Pathutil.new("/hello").fnmatch?("/hello") # => true
|
282
234
|
# Unlike traditional `fnmatch`, with this one `Regexp` is allowed.
|
283
|
-
#
|
284
|
-
#
|
285
|
-
# @example Pathutil.new("/hello").fnmatch?(/h/) # => true
|
286
|
-
# @return true, false
|
235
|
+
# Example: Pathutil.new("/hello").fnmatch?(/h/) # => true
|
236
|
+
# See: `File#fnmatch` for more information.
|
287
237
|
# --------------------------------------------------------------------------
|
288
238
|
|
289
239
|
def fnmatch?(matcher)
|
@@ -293,7 +243,6 @@ class Pathutil
|
|
293
243
|
|
294
244
|
# --------------------------------------------------------------------------
|
295
245
|
# Allows you to quickly determine if the file is the root folder.
|
296
|
-
# @return true, false
|
297
246
|
# --------------------------------------------------------------------------
|
298
247
|
|
299
248
|
def root?
|
@@ -301,9 +250,7 @@ class Pathutil
|
|
301
250
|
end
|
302
251
|
|
303
252
|
# --------------------------------------------------------------------------
|
304
|
-
# @param [Pathutil, String] path the reference.
|
305
253
|
# Allows you to check if the current path is in the path you want.
|
306
|
-
# @return true, false
|
307
254
|
# --------------------------------------------------------------------------
|
308
255
|
|
309
256
|
def in_path?(path)
|
@@ -321,7 +268,6 @@ class Pathutil
|
|
321
268
|
|
322
269
|
# --------------------------------------------------------------------------
|
323
270
|
# Grab all of the children from the current directory, including hidden.
|
324
|
-
# @return Array<Pathutils>
|
325
271
|
# --------------------------------------------------------------------------
|
326
272
|
|
327
273
|
def children
|
@@ -343,11 +289,8 @@ class Pathutil
|
|
343
289
|
end
|
344
290
|
|
345
291
|
# --------------------------------------------------------------------------
|
346
|
-
#
|
347
|
-
#
|
348
|
-
# @param [String] flags the flags you want to ship to the glob.
|
349
|
-
# @param [String] pattern the pattern A.K.A: "**/*"
|
350
|
-
# @return Enumerator unless a block is given.
|
292
|
+
# Allows you to glob however you wish to glob in the current `Pathutil`
|
293
|
+
# See: `File::Constants` for a list of flags.
|
351
294
|
# --------------------------------------------------------------------------
|
352
295
|
|
353
296
|
def glob(pattern, flags = 0)
|
@@ -369,9 +312,8 @@ class Pathutil
|
|
369
312
|
end
|
370
313
|
|
371
314
|
# --------------------------------------------------------------------------
|
372
|
-
# @note you do not need to ship a block at all.
|
373
315
|
# Move to the current directory temporarily (or for good) and do work son.
|
374
|
-
#
|
316
|
+
# Note: you do not need to ship a block at all.
|
375
317
|
# --------------------------------------------------------------------------
|
376
318
|
|
377
319
|
def chdir
|
@@ -388,9 +330,7 @@ class Pathutil
|
|
388
330
|
end
|
389
331
|
|
390
332
|
# --------------------------------------------------------------------------
|
391
|
-
# @return Enumerator if no block is given.
|
392
333
|
# Find all files without care and yield the given block.
|
393
|
-
# @see Find.find
|
394
334
|
# --------------------------------------------------------------------------
|
395
335
|
|
396
336
|
def find
|
@@ -402,7 +342,6 @@ class Pathutil
|
|
402
342
|
|
403
343
|
# --------------------------------------------------------------------------
|
404
344
|
# Splits the path returning each part (filename) back to you.
|
405
|
-
# @return Enumerator if no block is given.
|
406
345
|
# --------------------------------------------------------------------------
|
407
346
|
|
408
347
|
def each_filename
|
@@ -412,6 +351,9 @@ class Pathutil
|
|
412
351
|
end
|
413
352
|
end
|
414
353
|
|
354
|
+
# --------------------------------------------------------------------------
|
355
|
+
# Note: This will simply return self if "/".
|
356
|
+
# Get the parent of the current path.
|
415
357
|
# --------------------------------------------------------------------------
|
416
358
|
|
417
359
|
def parent
|
@@ -423,7 +365,6 @@ class Pathutil
|
|
423
365
|
|
424
366
|
# --------------------------------------------------------------------------
|
425
367
|
# Split the file into its dirname and basename, so you can do stuff.
|
426
|
-
# @return File.dirname, File.basename
|
427
368
|
# --------------------------------------------------------------------------
|
428
369
|
|
429
370
|
def split
|
@@ -434,6 +375,7 @@ class Pathutil
|
|
434
375
|
|
435
376
|
# --------------------------------------------------------------------------
|
436
377
|
# Replace a files extension with your given extension.
|
378
|
+
# Note: Your extension should start with "."
|
437
379
|
# --------------------------------------------------------------------------
|
438
380
|
|
439
381
|
def sub_ext(ext)
|
@@ -442,20 +384,18 @@ class Pathutil
|
|
442
384
|
|
443
385
|
# --------------------------------------------------------------------------
|
444
386
|
# A less complex version of `relative_path_from` that simply uses a
|
445
|
-
# `Regexp` and returns the full path if it cannot be
|
446
|
-
# @return Pathutils the relative path if it can be determined or is relative.
|
447
|
-
# @return Pathutils the full path if relative path cannot be determined
|
387
|
+
# `Regexp` and returns the full path if it cannot be determined.
|
448
388
|
# --------------------------------------------------------------------------
|
449
389
|
|
450
390
|
def relative_path_from(from)
|
451
391
|
from = self.class.new(from).expand_path.gsub(%r!/$!, "")
|
452
|
-
self.class.new(expand_path.gsub(%r!^#{
|
392
|
+
self.class.new(expand_path.gsub(%r!^#{
|
393
|
+
from.regexp_escape
|
394
|
+
}/!, ""))
|
453
395
|
end
|
454
396
|
|
455
397
|
# --------------------------------------------------------------------------
|
456
398
|
# Expands the path and left joins the root to the path.
|
457
|
-
# @param [String, Pathutil] root the root you wish to enforce on it.
|
458
|
-
# @return Pathutil the enforced path with given root.
|
459
399
|
# --------------------------------------------------------------------------
|
460
400
|
|
461
401
|
def enforce_root(root)
|
@@ -472,19 +412,28 @@ class Pathutil
|
|
472
412
|
|
473
413
|
# --------------------------------------------------------------------------
|
474
414
|
# Copy a directory, allowing symlinks if the link falls inside of the root.
|
415
|
+
# This is indented for people who wish some safety to their copies.
|
475
416
|
# --------------------------------------------------------------------------
|
476
417
|
|
477
418
|
def safe_copy(to, root: nil)
|
478
419
|
raise ArgumentError, "must give a root" unless root
|
479
|
-
to = self.class.new(to)
|
480
|
-
|
481
420
|
root = self.class.new(root)
|
482
|
-
|
483
|
-
|
421
|
+
to = self.class.new(to)
|
422
|
+
|
423
|
+
if directory?
|
424
|
+
safe_copy_directory(to, {
|
425
|
+
:root => root
|
426
|
+
})
|
427
|
+
|
428
|
+
else
|
429
|
+
safe_copy_file(to, {
|
430
|
+
:root => root
|
431
|
+
})
|
432
|
+
end
|
484
433
|
end
|
485
434
|
|
486
435
|
# --------------------------------------------------------------------------
|
487
|
-
#
|
436
|
+
# See: `self.class.normalize` as this is an alias.
|
488
437
|
# --------------------------------------------------------------------------
|
489
438
|
|
490
439
|
def normalize
|
@@ -494,7 +443,7 @@ class Pathutil
|
|
494
443
|
end
|
495
444
|
|
496
445
|
# --------------------------------------------------------------------------
|
497
|
-
#
|
446
|
+
# See: `self.class.encoding` as this is an alias.
|
498
447
|
# --------------------------------------------------------------------------
|
499
448
|
|
500
449
|
def encoding
|
@@ -505,6 +454,7 @@ class Pathutil
|
|
505
454
|
|
506
455
|
# --------------------------------------------------------------------------
|
507
456
|
# Read took two steroid shots: it can normalize your string, and encode.
|
457
|
+
# Note: You can set the default encodings via the class.
|
508
458
|
# --------------------------------------------------------------------------
|
509
459
|
|
510
460
|
def read(*args, **kwd)
|
@@ -524,6 +474,7 @@ class Pathutil
|
|
524
474
|
|
525
475
|
# --------------------------------------------------------------------------
|
526
476
|
# Binread took two steroid shots: it can normalize your string, and encode.
|
477
|
+
# Note: You can set the default encodings via the class.
|
527
478
|
# --------------------------------------------------------------------------
|
528
479
|
|
529
480
|
def binread(*args, **kwd)
|
@@ -543,6 +494,7 @@ class Pathutil
|
|
543
494
|
|
544
495
|
# --------------------------------------------------------------------------
|
545
496
|
# Readlines took two steroid shots: it can normalize your string, and encode.
|
497
|
+
# Note: You can set the default encodings via the class.
|
546
498
|
# --------------------------------------------------------------------------
|
547
499
|
|
548
500
|
def readlines(*args, **kwd)
|
@@ -562,6 +514,7 @@ class Pathutil
|
|
562
514
|
|
563
515
|
# --------------------------------------------------------------------------
|
564
516
|
# Write took two steroid shots: it can normalize your string, and encode.
|
517
|
+
# Note: You can set the default encodings via the class.
|
565
518
|
# --------------------------------------------------------------------------
|
566
519
|
|
567
520
|
def write(data, *args, **kwd)
|
@@ -581,6 +534,7 @@ class Pathutil
|
|
581
534
|
|
582
535
|
# --------------------------------------------------------------------------
|
583
536
|
# Binwrite took two steroid shots: it can normalize your string, and encode.
|
537
|
+
# Note: You can set the default encodings via the class.
|
584
538
|
# --------------------------------------------------------------------------
|
585
539
|
|
586
540
|
def binwrite(data, *args, **kwd)
|
@@ -599,7 +553,7 @@ class Pathutil
|
|
599
553
|
end
|
600
554
|
|
601
555
|
# --------------------------------------------------------------------------
|
602
|
-
#
|
556
|
+
# Expand the paths and return.
|
603
557
|
# --------------------------------------------------------------------------
|
604
558
|
|
605
559
|
private
|
@@ -607,6 +561,8 @@ class Pathutil
|
|
607
561
|
return expand_path, self.class.new(path).expand_path
|
608
562
|
end
|
609
563
|
|
564
|
+
# --------------------------------------------------------------------------
|
565
|
+
# Safely copy a file.
|
610
566
|
# --------------------------------------------------------------------------
|
611
567
|
|
612
568
|
private
|
@@ -617,6 +573,8 @@ class Pathutil
|
|
617
573
|
})
|
618
574
|
end
|
619
575
|
|
576
|
+
# --------------------------------------------------------------------------
|
577
|
+
# Safely copy a directory and it's sub-files.
|
620
578
|
# --------------------------------------------------------------------------
|
621
579
|
|
622
580
|
private
|
@@ -649,13 +607,12 @@ class Pathutil
|
|
649
607
|
end
|
650
608
|
end
|
651
609
|
|
652
|
-
# --------------------------------------------------------------------------
|
653
|
-
|
654
610
|
class << self
|
655
611
|
attr_writer :encoding
|
656
612
|
|
657
613
|
# ------------------------------------------------------------------------
|
658
614
|
# Get the current directory that Ruby knows about.
|
615
|
+
# Note: We do nothing special here.
|
659
616
|
# ------------------------------------------------------------------------
|
660
617
|
|
661
618
|
def pwd
|
@@ -668,9 +625,9 @@ class Pathutil
|
|
668
625
|
alias cwd pwd
|
669
626
|
|
670
627
|
# ------------------------------------------------------------------------
|
628
|
+
# Note: you are encouraged to override this if you need to.
|
671
629
|
# Aliases the default system encoding to us so that we can do most read
|
672
630
|
# and write operations with that encoding, instead of being crazy.
|
673
|
-
# @note you are encouraged to override this if you need to.
|
674
631
|
# ------------------------------------------------------------------------
|
675
632
|
|
676
633
|
def encoding
|
@@ -680,8 +637,8 @@ class Pathutil
|
|
680
637
|
end
|
681
638
|
|
682
639
|
# ------------------------------------------------------------------------
|
683
|
-
# Normalize CRLF -> LF
|
684
|
-
# Normalize LF
|
640
|
+
# Normalize CRLF -> LF on Windows reads, to ease your troubles.
|
641
|
+
# Normalize LF -> CLRF on Windows write, to ease your troubles.
|
685
642
|
# ------------------------------------------------------------------------
|
686
643
|
|
687
644
|
def normalize
|
@@ -691,6 +648,10 @@ class Pathutil
|
|
691
648
|
}
|
692
649
|
end
|
693
650
|
|
651
|
+
# ------------------------------------------------------------------------
|
652
|
+
# Make a temporary directory.
|
653
|
+
# Note: if you adruptly exit it will not remove the dir.
|
654
|
+
# Note: this directory is removed on exit.
|
694
655
|
# ------------------------------------------------------------------------
|
695
656
|
|
696
657
|
def tmpdir(*args)
|
@@ -702,6 +663,10 @@ class Pathutil
|
|
702
663
|
rtn
|
703
664
|
end
|
704
665
|
|
666
|
+
# ------------------------------------------------------------------------
|
667
|
+
# Make a temporary file.
|
668
|
+
# Note: if you adruptly exit it will not remove the dir.
|
669
|
+
# Note: this file is removed on exit.
|
705
670
|
# ------------------------------------------------------------------------
|
706
671
|
|
707
672
|
def tmpfile(*args)
|
@@ -812,8 +777,6 @@ class Pathutil
|
|
812
777
|
rb_delegate :shellescape, :to => :Shellwords, :args => :@path
|
813
778
|
rb_delegate :mkdir, :to => :Dir, :args => :@path
|
814
779
|
|
815
|
-
# --------------------------------------------------------------------------
|
816
|
-
# alias last basename, alias first dirname, alias ext extname
|
817
780
|
# --------------------------------------------------------------------------
|
818
781
|
|
819
782
|
alias + join
|
data/lib/pathutil/helpers.rb
CHANGED
@@ -4,7 +4,7 @@ class Pathutil
|
|
4
4
|
|
5
5
|
# ------------------------------------------------------------------------
|
6
6
|
# Wraps around YAML and SafeYAML to provide alternatives to Rubies.
|
7
|
-
#
|
7
|
+
# Note: We default aliases to yes so we can detect if you explicit true.
|
8
8
|
# ------------------------------------------------------------------------
|
9
9
|
|
10
10
|
def load_yaml(data, safe: true, whitelist_classes: [], whitelist_symbols: [], aliases: :yes)
|
@@ -32,6 +32,8 @@ class Pathutil
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
# ------------------------------------------------------------------------
|
36
|
+
# Make a temporary name suitable for temporary files and directories.
|
35
37
|
# ------------------------------------------------------------------------
|
36
38
|
|
37
39
|
def make_tmpname(prefix = "", suffix = nil, root = nil)
|
@@ -46,6 +48,7 @@ class Pathutil
|
|
46
48
|
|
47
49
|
# ------------------------------------------------------------------------
|
48
50
|
|
51
|
+
private
|
49
52
|
def tmpname_suffix(suffix)
|
50
53
|
suffix = suffix.join("-") if suffix.is_a?(Array)
|
51
54
|
suffix = suffix.gsub(/\A\-/, "") unless !suffix || suffix.empty?
|
@@ -53,6 +56,7 @@ class Pathutil
|
|
53
56
|
end
|
54
57
|
|
55
58
|
# ------------------------------------------------------------------------
|
59
|
+
# Cleanup the temp name prefix, joining if necessary.
|
56
60
|
# rubocop:disable Style/ParallelAssignment
|
57
61
|
# ------------------------------------------------------------------------
|
58
62
|
|
@@ -73,6 +77,7 @@ class Pathutil
|
|
73
77
|
end
|
74
78
|
|
75
79
|
# ------------------------------------------------------------------------
|
80
|
+
# Wrap around, cleanup, deprecate and use SafeYAML.
|
76
81
|
# rubocop:enable Style/ParallelAssignment
|
77
82
|
# ------------------------------------------------------------------------
|
78
83
|
|
data/lib/pathutil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwardable-extended
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.5'
|
27
27
|
description: Like Pathname but a little less insane.
|
28
28
|
email:
|
29
29
|
- jordon@envygeeks.io
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
60
|
+
rubygems_version: 2.6.2
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Almost like Pathname but just a little less insane.
|