libpath-ruby 0.2.2 → 0.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +33 -0
  3. data/README.md +25 -8
  4. data/examples/path_from_arg0.md +43 -43
  5. data/examples/path_from_arg0.rb +25 -23
  6. data/lib/libpath/constants/unix.rb +74 -74
  7. data/lib/libpath/constants/windows.rb +75 -75
  8. data/lib/libpath/constants.rb +20 -20
  9. data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +118 -118
  15. data/lib/libpath/form/windows.rb +228 -214
  16. data/lib/libpath/form.rb +20 -21
  17. data/lib/libpath/internal_/array.rb +57 -57
  18. data/lib/libpath/internal_/platform.rb +30 -31
  19. data/lib/libpath/internal_/string.rb +25 -20
  20. data/lib/libpath/internal_/unix/form.rb +124 -119
  21. data/lib/libpath/internal_/windows/drive.rb +80 -75
  22. data/lib/libpath/internal_/windows/form.rb +205 -194
  23. data/lib/libpath/libpath.rb +4 -1
  24. data/lib/libpath/path/unix.rb +120 -118
  25. data/lib/libpath/path/windows.rb +126 -124
  26. data/lib/libpath/path.rb +21 -21
  27. data/lib/libpath/util/unix.rb +261 -261
  28. data/lib/libpath/util/windows.rb +403 -403
  29. data/lib/libpath/util.rb +20 -20
  30. data/lib/libpath/version.rb +25 -26
  31. data/lib/libpath.rb +1 -1
  32. data/test/performance/benchmark_drive_letter.rb +50 -10
  33. data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
  34. data/test/performance/benchmark_rindex2.rb +56 -48
  35. data/test/performance/benchmark_split.rb +16 -10
  36. data/test/unit/compare/ts_all.rb +4 -4
  37. data/test/unit/equate/ts_all.rb +4 -4
  38. data/test/unit/equate/unix/ts_all.rb +4 -4
  39. data/test/unit/equate/windows/ts_all.rb +4 -4
  40. data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
  41. data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
  42. data/test/unit/exceptions/ts_all.rb +4 -4
  43. data/test/unit/form/tc_absolute_functions.rb +242 -240
  44. data/test/unit/form/ts_all.rb +4 -4
  45. data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
  46. data/test/unit/form/unix/ts_all.rb +4 -4
  47. data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
  48. data/test/unit/form/windows/ts_all.rb +4 -4
  49. data/test/unit/internal_/tc_array.rb +36 -32
  50. data/test/unit/internal_/ts_all.rb +4 -4
  51. data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
  52. data/test/unit/internal_/unix/form/ts_all.rb +4 -4
  53. data/test/unit/internal_/unix/tc_split_path.rb +387 -384
  54. data/test/unit/internal_/unix/ts_all.rb +4 -4
  55. data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
  56. data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
  57. data/test/unit/internal_/windows/form/ts_all.rb +4 -4
  58. data/test/unit/internal_/windows/tc_split_path.rb +874 -869
  59. data/test/unit/internal_/windows/ts_all.rb +4 -4
  60. data/test/unit/parse/ts_all.rb +4 -4
  61. data/test/unit/path/tc_path.rb +732 -732
  62. data/test/unit/path/ts_all.rb +4 -4
  63. data/test/unit/path/unix/tc_path.rb +544 -540
  64. data/test/unit/path/unix/ts_all.rb +4 -4
  65. data/test/unit/path/windows/tc_path.rb +608 -603
  66. data/test/unit/path/windows/ts_all.rb +4 -4
  67. data/test/unit/tc_version.rb +25 -22
  68. data/test/unit/ts_all.rb +4 -4
  69. data/test/unit/util/tc_combine_paths.rb +110 -105
  70. data/test/unit/util/tc_derive_relative_path.rb +8 -3
  71. data/test/unit/util/tc_make_path_canonical.rb +142 -138
  72. data/test/unit/util/ts_all.rb +4 -4
  73. data/test/unit/util/unix/tc_combine_paths.rb +38 -34
  74. data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
  75. data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
  76. data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
  77. data/test/unit/util/unix/ts_all.rb +4 -4
  78. data/test/unit/util/windows/tc_combine_paths.rb +82 -77
  79. data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
  80. data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
  81. data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
  82. data/test/unit/util/windows/ts_all.rb +4 -4
  83. metadata +9 -8
@@ -1,96 +1,96 @@
1
1
 
2
2
  # :stopdoc:
3
3
 
4
- module LibPath # :nodoc:
5
- # @!visibility private
6
- module Internal_ # :nodoc: all
7
4
 
5
+ module LibPath
8
6
  # @!visibility private
9
- module Array # :nodoc:
7
+ module Internal_ # :nodoc: all
10
8
 
11
- # @!visibility private
12
- def self.index(ar, v, after = nil) # :nodoc:
9
+ # @!visibility private
10
+ module Array # :nodoc:
13
11
 
14
- if after
12
+ # @!visibility private
13
+ def self.index(ar, v, after = nil) # :nodoc:
15
14
 
16
- if after < 0
15
+ if after
17
16
 
18
- after = ar.size + after
17
+ if after < 0
19
18
 
20
- return nil if after < 0
21
- else
19
+ after = ar.size + after
22
20
 
23
- return nil unless after < ar.size
24
- end
21
+ return nil if after < 0
22
+ else
25
23
 
26
- ar.each_with_index do |el, ix|
24
+ return nil unless after < ar.size
25
+ end
27
26
 
28
- if ix >= after
27
+ ar.each_with_index do |el, ix|
29
28
 
30
- if v == el
29
+ if ix >= after
31
30
 
32
- return ix
33
- end
34
- end
35
- end
31
+ if v == el
36
32
 
37
- nil
38
- else
33
+ return ix
34
+ end
35
+ end
36
+ end
39
37
 
40
- ar.index(v)
41
- end
42
- end
38
+ nil
39
+ else
43
40
 
44
- # @!visibility private
45
- def self.index2(ar, v1, v2, after = nil) # :nodoc:
41
+ ar.index(v)
42
+ end
43
+ end
46
44
 
47
- i_1 = self.index(ar, v1, after)
48
- i_2 = self.index(ar, v2, after)
45
+ # @!visibility private
46
+ def self.index2(ar, v1, v2, after = nil) # :nodoc:
49
47
 
50
- if i_1
48
+ i_1 = self.index(ar, v1, after)
49
+ i_2 = self.index(ar, v2, after)
51
50
 
52
- if i_2
51
+ if i_1
53
52
 
54
- i_1 < i_2 ? i_1 : i_2
55
- else
53
+ if i_2
56
54
 
57
- i_1
58
- end
59
- else
55
+ i_1 < i_2 ? i_1 : i_2
56
+ else
60
57
 
61
- i_2
62
- end
63
- end
58
+ i_1
59
+ end
60
+ else
64
61
 
62
+ i_2
63
+ end
64
+ end
65
65
 
66
- # @!visibility private
67
- def self.rindex2(ar, v1, v2) # :nodoc:
68
66
 
69
- i_1 = ar.rindex(v1)
70
- i_2 = ar.rindex(v2)
67
+ # @!visibility private
68
+ def self.rindex2(ar, v1, v2) # :nodoc:
71
69
 
72
- if i_1
70
+ i_1 = ar.rindex(v1)
71
+ i_2 = ar.rindex(v2)
73
72
 
74
- if i_2
73
+ if i_1
75
74
 
76
- i_1 < i_2 ? i_2 : i_1
77
- else
75
+ if i_2
78
76
 
79
- i_1
80
- end
81
- else
77
+ i_1 < i_2 ? i_2 : i_1
78
+ else
82
79
 
83
- i_2
84
- end
85
- end
80
+ i_1
81
+ end
82
+ else
86
83
 
87
- end
84
+ i_2
85
+ end
86
+ end
87
+ end # module Array
88
+ end # module Internal_
89
+ end # module LibPath
88
90
 
89
- end
90
- end
91
91
 
92
92
  # :startdoc:
93
93
 
94
- # ############################## end of file ############################# #
95
94
 
95
+ # ############################## end of file ############################# #
96
96
 
@@ -1,53 +1,52 @@
1
1
 
2
2
  # :stopdoc:
3
3
 
4
- module LibPath # :nodoc:
5
- # @!visibility private
6
- module Internal_ # :nodoc: all
7
4
 
5
+ module LibPath
8
6
  # @!visibility private
9
- module Platform # :nodoc: all
10
-
11
- # @!visibility private
12
- module OS_Internal_ # :nodoc: all
13
-
14
- # @!visibility private
15
- def self.win_platform_? # :nodoc:
7
+ module Internal_ # :nodoc: all
16
8
 
17
- return true if 'Windows_NT' == ENV['OS']
9
+ # @!visibility private
10
+ module Platform # :nodoc: all
18
11
 
19
- [
20
- 'bccwin',
21
- 'cygwin',
22
- 'djgpp',
23
- 'mingw',
24
- 'mswin',
25
- 'wince',
26
- ].each do |os_name|
12
+ # @!visibility private
13
+ module OS_Internal_ # :nodoc: all
27
14
 
28
- return true if /#{os_name}/i =~ RUBY_PLATFORM
29
- end
15
+ # @!visibility private
16
+ def self.win_platform_? # :nodoc:
30
17
 
31
- false
32
- end
18
+ return true if 'Windows_NT' == ENV['OS']
33
19
 
34
- end # module OS_Internal_
20
+ [
21
+ 'bccwin',
22
+ 'cygwin',
23
+ 'djgpp',
24
+ 'mingw',
25
+ 'mswin',
26
+ 'wince',
27
+ ].each do |os_name|
35
28
 
36
- # @!visibility private
37
- module Constants # :nodoc: all
29
+ return true if /#{os_name}/i =~ RUBY_PLATFORM
30
+ end
38
31
 
39
- # @!visibility private
40
- PLATFORM_IS_WINDOWS = OS_Internal_.win_platform_? # :nodoc:
32
+ false
33
+ end
34
+ end # module OS_Internal_
41
35
 
42
- end # module Constants
36
+ # @!visibility private
37
+ module Constants # :nodoc: all
43
38
 
44
- end # module Platform
39
+ # @!visibility private
40
+ PLATFORM_IS_WINDOWS = OS_Internal_.win_platform_? # :nodoc:
45
41
 
42
+ end # module Constants
43
+ end # module Platform
46
44
  end # module Internal_
47
45
  end # module LibPath
48
46
 
47
+
49
48
  # :startdoc:
50
49
 
51
- # ############################## end of file ############################# #
52
50
 
51
+ # ############################## end of file ############################# #
53
52
 
@@ -1,36 +1,41 @@
1
1
 
2
- module LibPath # :nodoc:
2
+ # :stopdoc:
3
+
4
+
5
+ module LibPath
3
6
  # @!visibility private
4
7
  module Internal_ # :nodoc: all
5
8
 
6
- module String # :nodoc:
9
+ # @!visibility private
10
+ module String # :nodoc:
7
11
 
8
- # @!visibility private
9
- def self.rindex2(s, c1, c2) # :nodoc:
12
+ # @!visibility private
13
+ def self.rindex2(s, c1, c2) # :nodoc:
10
14
 
11
- ri_1 = s.rindex(c1)
12
- ri_2 = s.rindex(c2)
15
+ ri_1 = s.rindex(c1)
16
+ ri_2 = s.rindex(c2)
13
17
 
14
- if ri_1
18
+ if ri_1
15
19
 
16
- if ri_2
20
+ if ri_2
17
21
 
18
- ri_1 < ri_2 ? ri_2 : ri_1
19
- else
22
+ ri_1 < ri_2 ? ri_2 : ri_1
23
+ else
20
24
 
21
- ri_1
22
- end
23
- else
25
+ ri_1
26
+ end
27
+ else
24
28
 
25
- ri_2
26
- end
27
- end
29
+ ri_2
30
+ end
31
+ end
32
+ end # module String
33
+ end # module Internal_
34
+ end # module LibPath
28
35
 
29
- end
30
36
 
31
- end
32
- end
37
+ # :startdoc:
33
38
 
34
- # ############################## end of file ############################# #
35
39
 
40
+ # ############################## end of file ############################# #
36
41
 
@@ -1,165 +1,170 @@
1
1
 
2
- module LibPath # :nodoc:
2
+ # :stopdoc:
3
+
4
+
5
+ module LibPath
3
6
  # @!visibility private
4
7
  module Internal_ # :nodoc: all
5
8
  # @!visibility private
6
9
  module Unix # :nodoc:
7
10
 
8
- # @!visibility private
9
- module Form # :nodoc:
10
-
11
- # [INTERNAL] This function is undocumented, and subject to change at any
12
- # time
13
- #
14
- # @!visibility private
15
- def self.char_is_path_name_separator? c # :nodoc:
16
-
17
- '/' == c
18
- end
19
-
20
- # [INTERNAL] This function is undocumented, and subject to change at any
21
- # time
22
- #
23
- # @!visibility private
24
- def self.append_trailing_slash s # :nodoc:
25
-
26
- return s if '/' == s[-1]
11
+ # @!visibility private
12
+ module Form # :nodoc:
13
+
14
+ # [INTERNAL] This function is undocumented, and subject to change at any
15
+ # time
16
+ #
17
+ # @!visibility private
18
+ def self.char_is_path_name_separator? c # :nodoc:
19
+
20
+ '/' == c
21
+ end
22
+
23
+ # [INTERNAL] This function is undocumented, and subject to change at any
24
+ # time
25
+ #
26
+ # @!visibility private
27
+ def self.append_trailing_slash s # :nodoc:
28
+
29
+ return s if '/' == s[-1]
27
30
 
28
- s + '/'
29
- end
31
+ s + '/'
32
+ end
30
33
 
31
- # [INTERNAL] This function is undocumented, and subject to change at any
32
- # time
33
- #
34
- # @!visibility private
35
- def self.get_trailing_slash s # :nodoc:
36
-
37
- '/' == s[-1] ? '/' : nil
38
- end
34
+ # [INTERNAL] This function is undocumented, and subject to change at any
35
+ # time
36
+ #
37
+ # @!visibility private
38
+ def self.get_trailing_slash s # :nodoc:
39
39
 
40
- # [INTERNAL] This function is undocumented, and subject to change at any
41
- # time
42
- #
43
- # @!visibility private
44
- def self.has_trailing_slash? s # :nodoc:
40
+ '/' == s[-1] ? '/' : nil
41
+ end
45
42
 
46
- '/' == s[-1]
47
- end
43
+ # [INTERNAL] This function is undocumented, and subject to change at any
44
+ # time
45
+ #
46
+ # @!visibility private
47
+ def self.has_trailing_slash? s # :nodoc:
48
48
 
49
- # [INTERNAL] This function is undocumented, and subject to change at any
50
- # time
51
- #
52
- # @!visibility private
53
- def self.trim_trailing_slash s # :nodoc:
49
+ '/' == s[-1]
50
+ end
54
51
 
55
- return s unless '/' == s[-1]
52
+ # [INTERNAL] This function is undocumented, and subject to change at any
53
+ # time
54
+ #
55
+ # @!visibility private
56
+ def self.trim_trailing_slash s # :nodoc:
56
57
 
57
- s.chop
58
- end
58
+ return s unless '/' == s[-1]
59
59
 
60
- # [INTERNAL] This function is undocumented, and subject to change at any
61
- # time
62
- #
63
- # @!visibility private
64
- def self.elide_redundant_path_name_separators s # :nodoc:
60
+ s.chop
61
+ end
65
62
 
66
- s.gsub(/\/\/+/, '/')
67
- end
63
+ # [INTERNAL] This function is undocumented, and subject to change at any
64
+ # time
65
+ #
66
+ # @!visibility private
67
+ def self.elide_redundant_path_name_separators s # :nodoc:
68
68
 
69
- # [INTERNAL] This function is undocumented, and subject to change at any
70
- # time
71
- #
72
- # @!visibility private
73
- def self.elide_redundant_path_name_separators! s # :nodoc:
69
+ s.gsub(/\/\/+/, '/')
70
+ end
74
71
 
75
- s.gsub!(/\/\/+/, '/')
72
+ # [INTERNAL] This function is undocumented, and subject to change at any
73
+ # time
74
+ #
75
+ # @!visibility private
76
+ def self.elide_redundant_path_name_separators! s # :nodoc:
76
77
 
77
- s
78
- end
78
+ s.gsub!(/\/\/+/, '/')
79
79
 
80
+ s
81
+ end
80
82
 
81
- # [INTERNAL] This function is undocumented, and subject to change at any
82
- # time
83
- #
84
- # Returns tuple of:
85
- #
86
- # 0. source path (with redundant path name separators elided)
87
- # 1. Windows volume (which is always nil)
88
- # 2. Directory
89
- # 3. Basename
90
- # 4. Stem
91
- # 5. Extension
92
- # 6. Directory parts
93
- # 7. Directory path parts
94
- #
95
- # @!visibility private
96
- def self.split_path s, **options # :nodoc:
97
83
 
98
- f2_directory = nil
99
- f3_basename = nil
100
- f4_stem = nil
101
- f5_extension = nil
102
- f6_dir_parts = []
84
+ # [INTERNAL] This function is undocumented, and subject to change at any
85
+ # time
86
+ #
87
+ # Returns tuple of:
88
+ #
89
+ # 0. source path (with redundant path name separators elided)
90
+ # 1. Windows volume (which is always nil)
91
+ # 2. Directory
92
+ # 3. Basename
93
+ # 4. Stem
94
+ # 5. Extension
95
+ # 6. Directory parts
96
+ # 7. Directory path parts
97
+ #
98
+ # @!visibility private
99
+ def self.split_path s, **options # :nodoc:
103
100
 
104
- s = self.elide_redundant_path_name_separators s
101
+ f2_directory = nil
102
+ f3_basename = nil
103
+ f4_stem = nil
104
+ f5_extension = nil
105
+ f6_dir_parts = []
105
106
 
106
- ri_slash = s.rindex('/')
107
+ s = self.elide_redundant_path_name_separators s
107
108
 
108
- if ri_slash
109
+ ri_slash = s.rindex('/')
109
110
 
110
- f2_directory = s[0..ri_slash]
111
- f3_basename = s[(1 + ri_slash)..-1]
112
- else
111
+ if ri_slash
113
112
 
114
- f2_directory = nil
115
- f3_basename = s
116
- end
113
+ f2_directory = s[0..ri_slash]
114
+ f3_basename = s[(1 + ri_slash)..-1]
115
+ else
117
116
 
118
- case f3_basename
119
- when '.', '..'
117
+ f2_directory = nil
118
+ f3_basename = s
119
+ end
120
120
 
121
- f4_stem = f3_basename
122
- f5_extension = nil
123
- else
121
+ case f3_basename
122
+ when '.', '..'
124
123
 
125
- ri_dot = f3_basename.rindex('.')
124
+ f4_stem = f3_basename
125
+ f5_extension = nil
126
+ else
126
127
 
127
- if ri_dot
128
+ ri_dot = f3_basename.rindex('.')
128
129
 
129
- f4_stem = f3_basename[0...ri_dot]
130
- f5_extension = f3_basename[ri_dot..-1]
131
- else
130
+ if ri_dot
132
131
 
133
- f4_stem = f3_basename
134
- f5_extension = nil
135
- end
136
- end
132
+ f4_stem = f3_basename[0...ri_dot]
133
+ f5_extension = f3_basename[ri_dot..-1]
134
+ else
137
135
 
138
- unless options[:suppress_parts]
136
+ f4_stem = f3_basename
137
+ f5_extension = nil
138
+ end
139
+ end
139
140
 
140
- case f2_directory
141
- when nil
141
+ unless options[:suppress_parts]
142
142
 
143
- ;
144
- when '/'
143
+ case f2_directory
144
+ when nil
145
145
 
146
- f6_dir_parts = [ '/' ]
147
- else
146
+ ;
147
+ when '/'
148
148
 
149
- f6_dir_parts = f2_directory.split('/').reject { |v| v.empty? }.map { |v| v + '/' }
150
- f6_dir_parts.unshift('/') if '/' == f2_directory[0]
151
- end
152
- end
149
+ f6_dir_parts = [ '/' ]
150
+ else
153
151
 
152
+ f6_dir_parts = f2_directory.split('/').reject { |v| v.empty? }.map { |v| v + '/' }
153
+ f6_dir_parts.unshift('/') if '/' == f2_directory[0]
154
+ end
155
+ end
154
156
 
155
- [ s, nil, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f6_dir_parts ].map { |v| ::String === v && v.empty? ? nil : v }
156
- end
157
- end # module Form
158
157
 
158
+ [ s, nil, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f6_dir_parts ].map { |v| ::String === v && v.empty? ? nil : v }
159
+ end
160
+ end # module Form
159
161
  end # module Unix
160
162
  end # module Internal_
161
163
  end # module LibPath
162
164
 
163
- # ############################## end of file ############################# #
164
165
 
166
+ # :startdoc:
167
+
168
+
169
+ # ############################## end of file ############################# #
165
170