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.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +74 -74
- data/lib/libpath/constants/windows.rb +75 -75
- data/lib/libpath/constants.rb +20 -20
- data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
- data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +118 -118
- data/lib/libpath/form/windows.rb +228 -214
- data/lib/libpath/form.rb +20 -21
- data/lib/libpath/internal_/array.rb +57 -57
- data/lib/libpath/internal_/platform.rb +30 -31
- data/lib/libpath/internal_/string.rb +25 -20
- data/lib/libpath/internal_/unix/form.rb +124 -119
- data/lib/libpath/internal_/windows/drive.rb +80 -75
- data/lib/libpath/internal_/windows/form.rb +205 -194
- data/lib/libpath/libpath.rb +4 -1
- data/lib/libpath/path/unix.rb +120 -118
- data/lib/libpath/path/windows.rb +126 -124
- data/lib/libpath/path.rb +21 -21
- data/lib/libpath/util/unix.rb +261 -261
- data/lib/libpath/util/windows.rb +403 -403
- data/lib/libpath/util.rb +20 -20
- data/lib/libpath/version.rb +25 -26
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
data/lib/libpath/form/unix.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: libpath/form/unix.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: LibPath::Form::Unix module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 8th January 2019
|
8
|
+
# Updated: 7th April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
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
|
-
|
59
|
-
|
60
|
-
module
|
55
|
+
module LibPath
|
56
|
+
module Form
|
57
|
+
module Unix
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
-
|
72
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
74
73
|
|
75
|
-
|
74
|
+
return nil if path.nil? || path.empty?
|
76
75
|
|
77
|
-
|
76
|
+
return :homed if path_is_homed? path
|
78
77
|
|
79
|
-
|
80
|
-
end
|
78
|
+
return :absolute if path_is_absolute? path
|
81
79
|
|
82
|
-
|
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
|
-
|
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
|
-
|
96
|
+
_Constants = ::LibPath::Constants::Unix
|
98
97
|
|
99
|
-
|
98
|
+
if name
|
100
99
|
|
101
|
-
|
102
|
-
end
|
100
|
+
if options[:reject_path_name_separators]
|
103
101
|
|
104
|
-
|
102
|
+
return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
|
103
|
+
end
|
105
104
|
|
106
|
-
|
107
|
-
end
|
105
|
+
if options[:reject_path_separators]
|
108
106
|
|
109
|
-
|
107
|
+
return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
|
108
|
+
end
|
110
109
|
|
111
|
-
|
112
|
-
end
|
110
|
+
if options[:reject_shell_characters]
|
113
111
|
|
114
|
-
|
112
|
+
return true if name =~ _Constants::InvalidCharacters::Shell::RE
|
113
|
+
end
|
115
114
|
|
116
|
-
|
117
|
-
else
|
115
|
+
return true if name =~ _Constants::InvalidCharacters::Innate::RE
|
118
116
|
|
119
|
-
|
120
|
-
|
121
|
-
end
|
117
|
+
false
|
118
|
+
else
|
122
119
|
|
123
|
-
|
124
|
-
|
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
|
-
|
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
|
-
|
135
|
-
when '/'
|
133
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
136
134
|
|
137
|
-
|
138
|
-
|
135
|
+
case path[0]
|
136
|
+
when '/'
|
139
137
|
|
140
|
-
|
141
|
-
|
138
|
+
true
|
139
|
+
when '~'
|
142
140
|
|
143
|
-
|
144
|
-
|
145
|
-
end
|
141
|
+
1 == path.size || '/' == path[1]
|
142
|
+
else
|
146
143
|
|
147
|
-
|
148
|
-
|
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
|
-
|
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
|
-
|
157
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
159
158
|
|
160
|
-
|
159
|
+
return false unless '~' == path[0]
|
161
160
|
|
162
|
-
|
163
|
-
end
|
161
|
+
if path.size > 1
|
164
162
|
|
165
|
-
|
166
|
-
|
163
|
+
return '/' == path[1]
|
164
|
+
end
|
167
165
|
|
168
|
-
|
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
|
-
|
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
|
-
|
180
|
-
end
|
178
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
181
179
|
|
182
|
-
|
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
|
-
|
187
|
+
receiver.class_eval do
|
188
188
|
|
189
|
-
|
190
|
-
|
189
|
+
extend LibPath_Form_Unix_Methods
|
190
|
+
end
|
191
191
|
|
192
|
-
|
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
|
-
|
198
|
+
receiver.class_eval do
|
199
199
|
|
200
|
-
|
201
|
-
|
200
|
+
include LibPath_Form_Unix_Methods
|
201
|
+
end
|
202
202
|
|
203
|
-
|
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
|
|