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
@@ -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: 6th 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,13 +45,13 @@
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
+
54
55
  module LibPath # :nodoc:
55
56
  module Form # :nodoc:
56
57
  module Unix # :nodoc:
@@ -59,148 +60,148 @@ module Unix # :nodoc:
59
60
  # any class or module including/extending module LibPath::Form::Unix
60
61
  module LibPath_Form_Unix_Methods
61
62
 
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
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
70
71
 
71
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
72
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
72
73
 
73
- return nil if path.nil? || path.empty?
74
+ return nil if path.nil? || path.empty?
74
75
 
75
- return :homed if path_is_homed? path
76
+ return :homed if path_is_homed? path
76
77
 
77
- return :absolute if path_is_absolute? path
78
+ return :absolute if path_is_absolute? path
78
79
 
79
- :relative
80
- end
80
+ :relative
81
+ end
81
82
 
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
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
94
95
 
95
- _Constants = ::LibPath::Constants::Unix
96
+ _Constants = ::LibPath::Constants::Unix
96
97
 
97
- if name
98
+ if name
98
99
 
99
- if options[:reject_path_name_separators]
100
+ if options[:reject_path_name_separators]
100
101
 
101
- return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
102
- end
102
+ return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
103
+ end
103
104
 
104
- if options[:reject_path_separators]
105
+ if options[:reject_path_separators]
105
106
 
106
- return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
107
- end
107
+ return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
108
+ end
108
109
 
109
- if options[:reject_shell_characters]
110
+ if options[:reject_shell_characters]
110
111
 
111
- return true if name =~ _Constants::InvalidCharacters::Shell::RE
112
- end
112
+ return true if name =~ _Constants::InvalidCharacters::Shell::RE
113
+ end
113
114
 
114
- return true if name =~ _Constants::InvalidCharacters::Innate::RE
115
+ return true if name =~ _Constants::InvalidCharacters::Innate::RE
115
116
 
116
- false
117
- else
117
+ false
118
+ else
118
119
 
119
- true
120
- end
121
- end
120
+ true
121
+ end
122
+ end
122
123
 
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
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
131
132
 
132
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
133
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
133
134
 
134
- case path[0]
135
- when '/'
135
+ case path[0]
136
+ when '/'
136
137
 
137
- true
138
- when '~'
138
+ true
139
+ when '~'
139
140
 
140
- 1 == path.size || '/' == path[1]
141
- else
141
+ 1 == path.size || '/' == path[1]
142
+ else
142
143
 
143
- false
144
- end
145
- end
144
+ false
145
+ end
146
+ end
146
147
 
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
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
155
156
 
156
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
157
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
157
158
 
158
- return false unless '~' == path[0]
159
+ return false unless '~' == path[0]
159
160
 
160
- if path.size > 1
161
+ if path.size > 1
161
162
 
162
- return '/' == path[1]
163
- end
163
+ return '/' == path[1]
164
+ end
164
165
 
165
- true
166
- end
166
+ true
167
+ end
167
168
 
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
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
176
177
 
177
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
178
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
178
179
 
179
- '/' == path[0]
180
- end
180
+ '/' == path[0]
181
+ end
181
182
 
182
183
  end # module LibPath_Form_Unix_Methods
183
184
 
184
185
  # @!visibility private
185
186
  def self.extended receiver # :nodoc:
186
187
 
187
- receiver.class_eval do
188
+ receiver.class_eval do
188
189
 
189
- extend LibPath_Form_Unix_Methods
190
- end
190
+ extend LibPath_Form_Unix_Methods
191
+ end
191
192
 
192
- $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
193
+ $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
193
194
  end
194
195
 
195
196
  # @!visibility private
196
197
  def self.included receiver # :nodoc:
197
198
 
198
- receiver.class_eval do
199
+ receiver.class_eval do
199
200
 
200
- include LibPath_Form_Unix_Methods
201
- end
201
+ include LibPath_Form_Unix_Methods
202
+ end
202
203
 
203
- $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
204
+ $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
204
205
  end
205
206
 
206
207
  extend LibPath_Form_Unix_Methods
@@ -210,6 +211,6 @@ end # module Unix
210
211
  end # module Form
211
212
  end # module LibPath
212
213
 
213
- # ############################## end of file ############################# #
214
214
 
215
+ # ############################## end of file ############################# #
215
216