libpath-ruby 0.2.2 → 0.2.2.2

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.
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,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: libpath/form/unix.rb
3
+ # File: libpath/form/unix.rb
4
4
  #
5
- # Purpose: LibPath::Form::Unix module
5
+ # Purpose: LibPath::Form::Unix module
6
6
  #
7
- # Created: 8th January 2019
8
- # Updated: 16th April 2019
7
+ # Created: 8th January 2019
8
+ # Updated: 7th April 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/libpath.Ruby
10
+ # Home: http://github.com/synesissoftware/libpath.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -44,172 +45,171 @@
44
45
  # ######################################################################## #
45
46
 
46
47
 
47
-
48
48
  =begin
49
49
  =end
50
50
 
51
51
  require 'libpath/constants/unix'
52
52
  require 'libpath/diagnostics'
53
53
 
54
- module LibPath # :nodoc:
55
- module Form # :nodoc:
56
- module Unix # :nodoc:
57
54
 
58
- # Module defining instance functions that will be included and extended into
59
- # any class or module including/extending module LibPath::Form::Unix
60
- module LibPath_Form_Unix_Methods
55
+ module LibPath
56
+ module Form
57
+ module Unix
61
58
 
62
- # Classifies a path
63
- #
64
- # === Return
65
- #
66
- # One of +:absolute+, +:homed+, +:relative+, for
67
- # any paths that match precisely those classifications, or +nil+ if the
68
- # path is empty
69
- def classify_path path
59
+ # Module defining instance functions that will be included and extended into
60
+ # any class or module including/extending module LibPath::Form::Unix
61
+ module LibPath_Form_Unix_Methods
70
62
 
71
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
63
+ # Classifies a path
64
+ #
65
+ # === Return
66
+ #
67
+ # One of +:absolute+, +:homed+, +:relative+, for
68
+ # any paths that match precisely those classifications, or +nil+ if the
69
+ # path is empty
70
+ def classify_path path
72
71
 
73
- return nil if path.nil? || path.empty?
72
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
74
73
 
75
- return :homed if path_is_homed? path
74
+ return nil if path.nil? || path.empty?
76
75
 
77
- return :absolute if path_is_absolute? path
76
+ return :homed if path_is_homed? path
78
77
 
79
- :relative
80
- end
78
+ return :absolute if path_is_absolute? path
81
79
 
82
- # Evaluates whether the given name is malformed
83
- #
84
- # === Signature
85
- #
86
- # * *Options:*
87
- # - +:reject_path_name_separators+:: (boolean) Reject the path
88
- # separator character(s): +'/'+
89
- # - +:reject_path_separators+:: (boolean) Reject the path separator
90
- # character(s): +':'+
91
- # - +:reject_shell_characters+:: (boolean) Reject the shell
92
- # character(s): +'*'+, +'?'+, +'|'+
93
- def name_is_malformed? name, **options
80
+ :relative
81
+ end
94
82
 
95
- _Constants = ::LibPath::Constants::Unix
83
+ # Evaluates whether the given name is malformed
84
+ #
85
+ # === Signature
86
+ #
87
+ # * *Options:*
88
+ # - +:reject_path_name_separators+:: (boolean) Reject the path
89
+ # separator character(s): +'/'+
90
+ # - +:reject_path_separators+:: (boolean) Reject the path separator
91
+ # character(s): +':'+
92
+ # - +:reject_shell_characters+:: (boolean) Reject the shell
93
+ # character(s): +'*'+, +'?'+, +'|'+
94
+ def name_is_malformed? name, **options
96
95
 
97
- if name
96
+ _Constants = ::LibPath::Constants::Unix
98
97
 
99
- if options[:reject_path_name_separators]
98
+ if name
100
99
 
101
- return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
102
- end
100
+ if options[:reject_path_name_separators]
103
101
 
104
- if options[:reject_path_separators]
102
+ return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
103
+ end
105
104
 
106
- return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
107
- end
105
+ if options[:reject_path_separators]
108
106
 
109
- if options[:reject_shell_characters]
107
+ return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
108
+ end
110
109
 
111
- return true if name =~ _Constants::InvalidCharacters::Shell::RE
112
- end
110
+ if options[:reject_shell_characters]
113
111
 
114
- return true if name =~ _Constants::InvalidCharacters::Innate::RE
112
+ return true if name =~ _Constants::InvalidCharacters::Shell::RE
113
+ end
115
114
 
116
- false
117
- else
115
+ return true if name =~ _Constants::InvalidCharacters::Innate::RE
118
116
 
119
- true
120
- end
121
- end
117
+ false
118
+ else
122
119
 
123
- # Evaluates whether the given path is absolute, which means it is either
124
- # rooted (begins with '/') or is homed (is '~' or begins with '~/')
125
- #
126
- # === Signature
127
- #
128
- # * *Parameters:*
129
- # - +path+:: (String) The path to be evaluated. May not be +nil+
130
- def path_is_absolute? path
120
+ true
121
+ end
122
+ end
131
123
 
132
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
124
+ # Evaluates whether the given path is absolute, which means it is either
125
+ # rooted (begins with '/') or is homed (is '~' or begins with '~/')
126
+ #
127
+ # === Signature
128
+ #
129
+ # * *Parameters:*
130
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
131
+ def path_is_absolute? path
133
132
 
134
- case path[0]
135
- when '/'
133
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
136
134
 
137
- true
138
- when '~'
135
+ case path[0]
136
+ when '/'
139
137
 
140
- 1 == path.size || '/' == path[1]
141
- else
138
+ true
139
+ when '~'
142
140
 
143
- false
144
- end
145
- end
141
+ 1 == path.size || '/' == path[1]
142
+ else
146
143
 
147
- # Evaluates whether the given path is homed, which means it is '~' or
148
- # begins with '~/'
149
- #
150
- # === Signature
151
- #
152
- # * *Parameters:*
153
- # - +path+:: (String) The path to be evaluated. May not be +nil+
154
- def path_is_homed? path
144
+ false
145
+ end
146
+ end
155
147
 
156
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
148
+ # Evaluates whether the given path is homed, which means it is '~' or
149
+ # begins with '~/'
150
+ #
151
+ # === Signature
152
+ #
153
+ # * *Parameters:*
154
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
155
+ def path_is_homed? path
157
156
 
158
- return false unless '~' == path[0]
157
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
159
158
 
160
- if path.size > 1
159
+ return false unless '~' == path[0]
161
160
 
162
- return '/' == path[1]
163
- end
161
+ if path.size > 1
164
162
 
165
- true
166
- end
163
+ return '/' == path[1]
164
+ end
167
165
 
168
- # Evalutes whether the given path is rooted, which means it begins with
169
- # '/'
170
- #
171
- # === Signature
172
- #
173
- # * *Parameters:*
174
- # - +path+:: (String) The path to be evaluated. May not be +nil+
175
- def path_is_rooted? path
166
+ true
167
+ end
176
168
 
177
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
169
+ # Evalutes whether the given path is rooted, which means it begins with
170
+ # '/'
171
+ #
172
+ # === Signature
173
+ #
174
+ # * *Parameters:*
175
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
176
+ def path_is_rooted? path
178
177
 
179
- '/' == path[0]
180
- end
178
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
181
179
 
182
- end # module LibPath_Form_Unix_Methods
180
+ '/' == path[0]
181
+ end
182
+ end # module LibPath_Form_Unix_Methods
183
183
 
184
- # @!visibility private
185
- def self.extended receiver # :nodoc:
184
+ # @!visibility private
185
+ def self.extended receiver # :nodoc:
186
186
 
187
- receiver.class_eval do
187
+ receiver.class_eval do
188
188
 
189
- extend LibPath_Form_Unix_Methods
190
- end
189
+ extend LibPath_Form_Unix_Methods
190
+ end
191
191
 
192
- $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
193
- end
192
+ $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
193
+ end
194
194
 
195
- # @!visibility private
196
- def self.included receiver # :nodoc:
195
+ # @!visibility private
196
+ def self.included receiver # :nodoc:
197
197
 
198
- receiver.class_eval do
198
+ receiver.class_eval do
199
199
 
200
- include LibPath_Form_Unix_Methods
201
- end
200
+ include LibPath_Form_Unix_Methods
201
+ end
202
202
 
203
- $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
204
- end
203
+ $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
204
+ end
205
205
 
206
- extend LibPath_Form_Unix_Methods
207
- include LibPath_Form_Unix_Methods
206
+ extend LibPath_Form_Unix_Methods
207
+ include LibPath_Form_Unix_Methods
208
208
 
209
209
  end # module Unix
210
210
  end # module Form
211
211
  end # module LibPath
212
212
 
213
- # ############################## end of file ############################# #
214
213
 
214
+ # ############################## end of file ############################# #
215
215