pathutil 0.12.0 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7adeba9b30c364e3ee44b710c116d6b8f5c1618e
4
- data.tar.gz: c411f1581b9aa43bb8950b8152996214b0f3d439
3
+ metadata.gz: 998b0160c81f9d70824ce3ee6bee7bc6021bdbb1
4
+ data.tar.gz: 7920dceb659c96586f4e74c39185a14a9e802deb
5
5
  SHA512:
6
- metadata.gz: f4098b97bc4f98a84a09dbc229c7ebe0e79577d5606fbc31ca2870268d8ecd905793bfe07d40e2a40ccb3d2cfbef1e2616029e61e4e2d1bf97cae9be8424577c
7
- data.tar.gz: b906af65d158da1a5cf5178330d3e2cd899e1b74c640c9e59f7372a2b099203d4a677c3b200c11c8a7408f095937c92fdb4e52deccdd4b74a2c079acaa34e602
6
+ metadata.gz: 90d19782deb8cf0a436d6cc595a21d4e705f4fbfe32dfb20b7cbc4a518fe817f0f7c7117a3a5ed03dc39b20ed09aa96ca708716a845be448bbed4f18e0ed1479
7
+ data.tar.gz: af99f3f934c28c2770f2feab2cdfc59c77512fc9a064edca968cca3474d10257dff75a2a40ad7ef17dc39ae5d0fd0b7b122c82765dba31ae60c20aa4ed487beb
data/lib/pathutil.rb CHANGED
@@ -22,6 +22,28 @@ class Pathutil
22
22
  return @path = path.to_s
23
23
  end
24
24
 
25
+ # --
26
+ # Make a path relative.
27
+ # --
28
+
29
+ def relative
30
+ return self if relative?
31
+ self.class.new(strip_windows_drive.gsub(
32
+ %r!\A(\\+|/+)!, ""
33
+ ))
34
+ end
35
+
36
+ # --
37
+ # Make a path absolute
38
+ # --
39
+
40
+ def absolute
41
+ return self if absolute?
42
+ self.class.new("/").join(
43
+ @path
44
+ )
45
+ end
46
+
25
47
  # --
26
48
  # @see Pathname#cleanpath.
27
49
  # @note This is a wholesale rip and cleanup of Pathname#cleanpath
@@ -172,7 +194,9 @@ class Pathutil
172
194
  # @return true|false
173
195
  # --
174
196
  def absolute?
175
- @path.start_with?("/")
197
+ return !!(
198
+ @path =~ %r!\A(?:[A-Za-z]:)?(?:\\+|/+)!
199
+ )
176
200
  end
177
201
 
178
202
  # --
@@ -417,15 +441,10 @@ class Pathutil
417
441
  # @return Pathutil
418
442
  # --
419
443
  def enforce_root(root)
420
- curr, root = expanded_paths(root)
421
- if curr.in_path?(root)
422
- return curr
423
-
424
- else
425
- Pathutil.new(File.join(
426
- root, curr
427
- ))
428
- end
444
+ return self if in_path?(root)
445
+ self.class.new(root).join(
446
+ self
447
+ )
429
448
  end
430
449
 
431
450
  # --
@@ -577,6 +596,16 @@ class Pathutil
577
596
  ))
578
597
  end
579
598
 
599
+ # --
600
+ # Strips the windows drive from the path.
601
+ # --
602
+
603
+ def strip_windows_drive(path = @path)
604
+ self.class.new(path.gsub(
605
+ %r!\A[A-Za-z]:(?:\\+|/+)!, ""
606
+ ))
607
+ end
608
+
580
609
  # --
581
610
  # rubocop:disable Metrics/AbcSize
582
611
  # rubocop:disable Metrics/CyclomaticComplexity
@@ -625,7 +654,8 @@ class Pathutil
625
654
 
626
655
  return self.class.new("/") if _out == [""].freeze
627
656
  return self.class.new(".") if _out.empty? && (end_with?(".") || relative?)
628
- return self.class.new(_out.join("/")).join("") if @path =~ %r!/\z! && _out.last != "." && _out.last != ".."
657
+ return self.class.new(_out.join("/")).join("") if @path =~ %r!/\z! \
658
+ && _out.last != "." && _out.last != ".."
629
659
  self.class.new(_out.join("/"))
630
660
  end
631
661
 
@@ -868,6 +898,7 @@ class Pathutil
868
898
  alias make_symlink symlink
869
899
  alias cleanpath_conservative conservative_cleanpath
870
900
  alias cleanpath_aggressive aggressive_cleanpath
901
+ alias prepend enforce_root
871
902
  alias fnmatch fnmatch?
872
903
  alias make_link link
873
904
  alias first dirname
@@ -3,5 +3,5 @@
3
3
  # Encoding: utf-8
4
4
 
5
5
  class Pathutil
6
- VERSION = "0.12.0"
6
+ VERSION = "0.13.0"
7
7
  end
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.12.0
4
+ version: 0.13.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-05-14 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forwardable-extended