libpath-ruby 0.2.2 → 0.2.2.1

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 +71 -71
  7. data/lib/libpath/constants/windows.rb +72 -72
  8. data/lib/libpath/constants.rb +18 -19
  9. data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +104 -103
  15. data/lib/libpath/form/windows.rb +200 -199
  16. data/lib/libpath/form.rb +18 -18
  17. data/lib/libpath/internal_/array.rb +53 -53
  18. data/lib/libpath/internal_/platform.rb +24 -24
  19. data/lib/libpath/internal_/string.rb +18 -18
  20. data/lib/libpath/internal_/unix/form.rb +116 -116
  21. data/lib/libpath/internal_/windows/drive.rb +59 -59
  22. data/lib/libpath/internal_/windows/form.rb +189 -189
  23. data/lib/libpath/libpath.rb +3 -0
  24. data/lib/libpath/path/unix.rb +114 -112
  25. data/lib/libpath/path/windows.rb +120 -118
  26. data/lib/libpath/path.rb +18 -20
  27. data/lib/libpath/util/unix.rb +258 -258
  28. data/lib/libpath/util/windows.rb +400 -400
  29. data/lib/libpath/util.rb +18 -19
  30. data/lib/libpath/version.rb +23 -24
  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
@@ -11,276 +11,276 @@ module Windows # :nodoc:
11
11
  # @!visibility private
12
12
  module Form # :nodoc:
13
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:
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
19
 
20
- '/' == c || '\\' == c
21
- end
20
+ '/' == c || '\\' == c
21
+ end
22
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:
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
28
 
29
- return s if self.char_is_path_name_separator?(s[-1])
29
+ return s if self.char_is_path_name_separator?(s[-1])
30
30
 
31
- s + '\\'
32
- end
31
+ s + '\\'
32
+ end
33
33
 
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:
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
- last = s[-1]
40
+ last = s[-1]
41
41
 
42
- self.char_is_path_name_separator?(last) ? last : nil
43
- end
42
+ self.char_is_path_name_separator?(last) ? last : nil
43
+ end
44
44
 
45
- # [INTERNAL] This function is undocumented, and subject to change at any
46
- # time
47
- #
48
- # @!visibility private
49
- def self.has_trailing_slash? s # :nodoc:
45
+ # [INTERNAL] This function is undocumented, and subject to change at any
46
+ # time
47
+ #
48
+ # @!visibility private
49
+ def self.has_trailing_slash? s # :nodoc:
50
50
 
51
- self.char_is_path_name_separator?(s[-1])
52
- end
51
+ self.char_is_path_name_separator?(s[-1])
52
+ end
53
53
 
54
- # [INTERNAL] This function is undocumented, and subject to change at any
55
- # time
56
- #
57
- # @!visibility private
58
- def self.trim_trailing_slash s # :nodoc:
54
+ # [INTERNAL] This function is undocumented, and subject to change at any
55
+ # time
56
+ #
57
+ # @!visibility private
58
+ def self.trim_trailing_slash s # :nodoc:
59
59
 
60
- return s unless self.char_is_path_name_separator?(s[-1])
60
+ return s unless self.char_is_path_name_separator?(s[-1])
61
61
 
62
- s.chop
63
- end
62
+ s.chop
63
+ end
64
64
 
65
- # [INTERNAL] This function is undocumented, and subject to change at any
66
- # time
67
- #
68
- # @!visibility private
69
- def self.elide_redundant_path_name_separators s # :nodoc:
65
+ # [INTERNAL] This function is undocumented, and subject to change at any
66
+ # time
67
+ #
68
+ # @!visibility private
69
+ def self.elide_redundant_path_name_separators s # :nodoc:
70
70
 
71
- s.gsub(/[\\\/]{2,}/, '\\')
72
- end
71
+ s.gsub(/[\\\/]{2,}/, '\\')
72
+ end
73
73
 
74
- # [INTERNAL] This function is undocumented, and subject to change at any
75
- # time
76
- #
77
- # @!visibility private
78
- def self.elide_redundant_path_name_separators! s # :nodoc:
74
+ # [INTERNAL] This function is undocumented, and subject to change at any
75
+ # time
76
+ #
77
+ # @!visibility private
78
+ def self.elide_redundant_path_name_separators! s # :nodoc:
79
79
 
80
- s.gsub!(/[\\\/]{2,}/, '\\')
80
+ s.gsub!(/[\\\/]{2,}/, '\\')
81
81
 
82
- s
83
- end
82
+ s
83
+ end
84
84
 
85
- # [INTERNAL] This function is undocumented, and subject to change at any
86
- # time
87
- #
88
- # === Signature
89
- #
90
- # * *Parameters:*
91
- # - +s+ (String)
92
- #
93
- # === Return
94
- # A 3-element array, consisting of [ volume, remainder, form ]
95
- #
96
- # @!visibility private
97
- def self.get_windows_volume s # :nodoc:
85
+ # [INTERNAL] This function is undocumented, and subject to change at any
86
+ # time
87
+ #
88
+ # === Signature
89
+ #
90
+ # * *Parameters:*
91
+ # - +s+ (String)
92
+ #
93
+ # === Return
94
+ # A 3-element array, consisting of [ volume, remainder, form ]
95
+ #
96
+ # @!visibility private
97
+ def self.get_windows_volume s # :nodoc:
98
98
 
99
- # 0. not matched
100
- # 1. X:
101
- # 2. \\server\share
102
- # 3. \\?\X:
103
- # 4. \\?\server\share
104
- # 5. \\?\UNC\server\share
105
- # 6. \\.\device
99
+ # 0. not matched
100
+ # 1. X:
101
+ # 2. \\server\share
102
+ # 3. \\?\X:
103
+ # 4. \\?\server\share
104
+ # 5. \\?\UNC\server\share
105
+ # 6. \\.\device
106
106
 
107
- if '\\' == s[0]
107
+ if '\\' == s[0]
108
108
 
109
- if '\\' == s[1]
109
+ if '\\' == s[1]
110
110
 
111
- case s[2]
112
- when '?'
111
+ case s[2]
112
+ when '?'
113
113
 
114
- if '\\' == s[3]
114
+ if '\\' == s[3]
115
115
 
116
- if ':' == s[5] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[4])
116
+ if ':' == s[5] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[4])
117
117
 
118
- # 3. \\?\X:
118
+ # 3. \\?\X:
119
119
 
120
- return [ s[0..5], s[6..-1], :form_3 ]
121
- end
120
+ return [ s[0..5], s[6..-1], :form_3 ]
121
+ end
122
122
 
123
- if 'U' == s[4] && 'N' == s[5] && 'C' == s[6]
123
+ if 'U' == s[4] && 'N' == s[5] && 'C' == s[6]
124
124
 
125
- # 5. \\?\UNC\server\share
125
+ # 5. \\?\UNC\server\share
126
126
 
127
- if s =~ /^\\\\\?\\UNC\\[^\\]+\\[^\\\/]+/
127
+ if s =~ /^\\\\\?\\UNC\\[^\\]+\\[^\\\/]+/
128
128
 
129
- return [ $&, $', :form_5 ]
130
- end
131
- else
129
+ return [ $&, $', :form_5 ]
130
+ end
131
+ else
132
132
 
133
- if s =~ /^\\\\\?\\[^\\]+\\[^\\\/]+/
133
+ if s =~ /^\\\\\?\\[^\\]+\\[^\\\/]+/
134
134
 
135
- # 4. \\?\server\share
135
+ # 4. \\?\server\share
136
136
 
137
- return [ $&, $', :form_4 ]
138
- end
139
- end
137
+ return [ $&, $', :form_4 ]
138
+ end
139
+ end
140
140
 
141
- return [ s, '', :malformed ]
142
- end
143
- when '.'
141
+ return [ s, '', :malformed ]
142
+ end
143
+ when '.'
144
144
 
145
- if s =~ /^\\\\\.\\[^\\]+/
145
+ if s =~ /^\\\\\.\\[^\\]+/
146
146
 
147
- # 6. \\.\device
147
+ # 6. \\.\device
148
148
 
149
- return [ $&, $', :form_6 ]
150
- end
151
- else
149
+ return [ $&, $', :form_6 ]
150
+ end
151
+ else
152
152
 
153
- if s =~ /^\\\\[^\\]+\\[^\\\/]+/
153
+ if s =~ /^\\\\[^\\]+\\[^\\\/]+/
154
154
 
155
- # 2. \\server\share
155
+ # 2. \\server\share
156
156
 
157
- return [ $&, $', :form_2 ]
158
- end
159
- end
160
- else
157
+ return [ $&, $', :form_2 ]
158
+ end
159
+ end
160
+ else
161
161
 
162
- end
163
- elsif ':' == s[1] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[0])
162
+ end
163
+ elsif ':' == s[1] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[0])
164
164
 
165
- # 1. X:
165
+ # 1. X:
166
166
 
167
- return [ s[0..1], s[2..-1], :form_1 ]
168
- end
167
+ return [ s[0..1], s[2..-1], :form_1 ]
168
+ end
169
169
 
170
- # 0. not matched
170
+ # 0. not matched
171
171
 
172
- [ nil, s, :form_0 ]
173
- end
172
+ [ nil, s, :form_0 ]
173
+ end
174
174
 
175
- # [INTERNAL] This function is undocumented, and subject to change at any
176
- # time
177
- #
178
- # Returns tuple of:
179
- #
180
- # 0. source path (with redundant path name separators elided)
181
- # 1. Windows volume (which is always nil)
182
- # 2. Directory
183
- # 3. Basename
184
- # 4. Stem
185
- # 5. Extension
186
- # 6. Directory parts
187
- # 7. Directory path parts
188
- #
189
- # @!visibility private
190
- def self.split_path s # :nodoc:
175
+ # [INTERNAL] This function is undocumented, and subject to change at any
176
+ # time
177
+ #
178
+ # Returns tuple of:
179
+ #
180
+ # 0. source path (with redundant path name separators elided)
181
+ # 1. Windows volume (which is always nil)
182
+ # 2. Directory
183
+ # 3. Basename
184
+ # 4. Stem
185
+ # 5. Extension
186
+ # 6. Directory parts
187
+ # 7. Directory path parts
188
+ #
189
+ # @!visibility private
190
+ def self.split_path s # :nodoc:
191
191
 
192
- f1_volume = nil
193
- f2_directory = nil
194
- f3_basename = nil
195
- f4_stem = nil
196
- f5_extension = nil
197
- f6_dir_parts = []
198
- f7_all_parts = []
192
+ f1_volume = nil
193
+ f2_directory = nil
194
+ f3_basename = nil
195
+ f4_stem = nil
196
+ f5_extension = nil
197
+ f6_dir_parts = []
198
+ f7_all_parts = []
199
199
 
200
- f1_volume, rem, frm = self.get_windows_volume s
200
+ f1_volume, rem, frm = self.get_windows_volume s
201
201
 
202
- self.elide_redundant_path_name_separators! rem
202
+ self.elide_redundant_path_name_separators! rem
203
203
 
204
- f1_volume.define_singleton_method(:form) { frm } if f1_volume
204
+ f1_volume.define_singleton_method(:form) { frm } if f1_volume
205
205
 
206
- if :malformed == frm
206
+ if :malformed == frm
207
207
 
208
- return [ s, f1_volume, nil, nil, nil, nil, [], [] ]
209
- end
208
+ return [ s, f1_volume, nil, nil, nil, nil, [], [] ]
209
+ end
210
210
 
211
- unless rem.empty?
211
+ unless rem.empty?
212
212
 
213
- ri_slash = ::LibPath::Internal_::String.rindex2(rem, '/', '\\')
213
+ ri_slash = ::LibPath::Internal_::String.rindex2(rem, '/', '\\')
214
214
 
215
- if ri_slash
215
+ if ri_slash
216
216
 
217
- f2_directory = rem[0..ri_slash]
218
- f3_basename = rem[(1 + ri_slash)..-1]
219
- else
217
+ f2_directory = rem[0..ri_slash]
218
+ f3_basename = rem[(1 + ri_slash)..-1]
219
+ else
220
220
 
221
- f2_directory = nil
222
- f3_basename = rem
223
- end
221
+ f2_directory = nil
222
+ f3_basename = rem
223
+ end
224
224
 
225
- case f3_basename
226
- when '.', '..'
225
+ case f3_basename
226
+ when '.', '..'
227
227
 
228
- f4_stem = f3_basename
229
- f5_extension = nil
230
- else
228
+ f4_stem = f3_basename
229
+ f5_extension = nil
230
+ else
231
231
 
232
- ri_dot = f3_basename.rindex('.')
232
+ ri_dot = f3_basename.rindex('.')
233
233
 
234
- if ri_dot
234
+ if ri_dot
235
235
 
236
- f4_stem = f3_basename[0...ri_dot]
237
- f5_extension = f3_basename[ri_dot..-1]
238
- else
236
+ f4_stem = f3_basename[0...ri_dot]
237
+ f5_extension = f3_basename[ri_dot..-1]
238
+ else
239
239
 
240
- f4_stem = f3_basename
241
- f5_extension = nil
242
- end
243
- end
240
+ f4_stem = f3_basename
241
+ f5_extension = nil
242
+ end
243
+ end
244
244
 
245
- case f2_directory
246
- when nil
245
+ case f2_directory
246
+ when nil
247
247
 
248
- ;
249
- when '\\', '/'
248
+ ;
249
+ when '\\', '/'
250
250
 
251
- f6_dir_parts = [ f2_directory ]
252
- else
251
+ f6_dir_parts = [ f2_directory ]
252
+ else
253
253
 
254
- parts = f2_directory.split(/([\\\/])/)
254
+ parts = f2_directory.split(/([\\\/])/)
255
255
 
256
- f6_dir_parts = []
256
+ f6_dir_parts = []
257
257
 
258
- (0...(parts.size / 2)).each do |ix|
258
+ (0...(parts.size / 2)).each do |ix|
259
259
 
260
- f6_dir_parts << parts[2 * ix + 0] + parts[2 * ix + 1]
261
- end
262
- end
260
+ f6_dir_parts << parts[2 * ix + 0] + parts[2 * ix + 1]
261
+ end
262
+ end
263
263
 
264
- if f1_volume
264
+ if f1_volume
265
265
 
266
- f7_all_parts = f6_dir_parts.dup
266
+ f7_all_parts = f6_dir_parts.dup
267
267
 
268
- f7_all_parts[0] = f1_volume + f7_all_parts[0].to_s
269
- else
268
+ f7_all_parts[0] = f1_volume + f7_all_parts[0].to_s
269
+ else
270
270
 
271
- f7_all_parts = f6_dir_parts
272
- end
273
- end
271
+ f7_all_parts = f6_dir_parts
272
+ end
273
+ end
274
274
 
275
275
 
276
- [ "#{f1_volume}#{rem}", f1_volume, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f7_all_parts ].map { |v| ::String === v && v.empty? ? nil : v }
277
- end
276
+ [ "#{f1_volume}#{rem}", f1_volume, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f7_all_parts ].map { |v| ::String === v && v.empty? ? nil : v }
277
+ end
278
278
  end # module Form
279
279
 
280
280
  end # module Windows
281
281
  end # module Internal_
282
282
  end # module LibPath
283
283
 
284
- # ############################## end of file ############################# #
285
284
 
285
+ # ############################## end of file ############################# #
286
286
 
@@ -4,3 +4,6 @@ module LibPath
4
4
 
5
5
  end # module LibPath
6
6
 
7
+
8
+ # ############################## end of file ############################# #
9
+