libpath-ruby 0.2.2.1 → 0.2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/libpath/constants/unix.rb +66 -66
- data/lib/libpath/constants/windows.rb +67 -67
- data/lib/libpath/constants.rb +3 -2
- data/lib/libpath/diagnostics/parameter_checking.rb +2 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +12 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +21 -22
- data/lib/libpath/form/unix.rb +110 -111
- data/lib/libpath/form/windows.rb +208 -195
- data/lib/libpath/form.rb +2 -3
- data/lib/libpath/internal_/array.rb +48 -48
- data/lib/libpath/internal_/platform.rb +26 -27
- data/lib/libpath/internal_/string.rb +22 -17
- data/lib/libpath/internal_/unix/form.rb +118 -113
- data/lib/libpath/internal_/windows/drive.rb +76 -71
- data/lib/libpath/internal_/windows/form.rb +206 -195
- data/lib/libpath/libpath.rb +1 -1
- data/lib/libpath/path/unix.rb +106 -106
- data/lib/libpath/path/windows.rb +101 -101
- data/lib/libpath/path.rb +3 -1
- data/lib/libpath/util/unix.rb +7 -7
- data/lib/libpath/util/windows.rb +7 -7
- data/lib/libpath/util.rb +3 -2
- data/lib/libpath/version.rb +9 -9
- data/test/performance/benchmark_rindex2.rb +7 -7
- data/test/unit/exceptions/tc_malformed_name_exception.rb +2 -2
- data/test/unit/path/tc_path.rb +0 -2
- metadata +2 -2
data/lib/libpath/form/unix.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: LibPath::Form::Unix module
|
6
6
|
#
|
7
7
|
# Created: 8th January 2019
|
8
|
-
# Updated:
|
8
|
+
# Updated: 13th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
11
|
#
|
@@ -45,167 +45,166 @@
|
|
45
45
|
# ######################################################################## #
|
46
46
|
|
47
47
|
|
48
|
-
=begin
|
49
|
-
=end
|
50
|
-
|
51
48
|
require 'libpath/constants/unix'
|
52
49
|
require 'libpath/diagnostics'
|
53
50
|
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
module Unix # :nodoc:
|
52
|
+
=begin
|
53
|
+
=end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
module
|
55
|
+
module LibPath
|
56
|
+
module Form
|
57
|
+
module Unix
|
62
58
|
|
63
|
-
#
|
64
|
-
#
|
65
|
-
|
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
|
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
|
71
62
|
|
72
|
-
|
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
|
73
71
|
|
74
|
-
|
72
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
75
73
|
|
76
|
-
|
74
|
+
return nil if path.nil? || path.empty?
|
77
75
|
|
78
|
-
|
76
|
+
return :homed if path_is_homed? path
|
79
77
|
|
80
|
-
|
81
|
-
|
78
|
+
return :absolute if path_is_absolute? path
|
79
|
+
|
80
|
+
:relative
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
95
95
|
|
96
|
-
|
96
|
+
_Constants = ::LibPath::Constants::Unix
|
97
97
|
|
98
|
-
|
98
|
+
if name
|
99
99
|
|
100
|
-
|
100
|
+
if options[:reject_path_name_separators]
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
|
103
|
+
end
|
104
104
|
|
105
|
-
|
105
|
+
if options[:reject_path_separators]
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
|
108
|
+
end
|
109
109
|
|
110
|
-
|
110
|
+
if options[:reject_shell_characters]
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
return true if name =~ _Constants::InvalidCharacters::Shell::RE
|
113
|
+
end
|
114
114
|
|
115
|
-
|
115
|
+
return true if name =~ _Constants::InvalidCharacters::Innate::RE
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
false
|
118
|
+
else
|
119
119
|
|
120
|
-
|
120
|
+
true
|
121
|
+
end
|
121
122
|
end
|
122
|
-
end
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
132
132
|
|
133
|
-
|
133
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
case path[0]
|
136
|
+
when '/'
|
137
137
|
|
138
|
-
|
139
|
-
|
138
|
+
true
|
139
|
+
when '~'
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
1 == path.size || '/' == path[1]
|
142
|
+
else
|
143
143
|
|
144
|
-
|
144
|
+
false
|
145
|
+
end
|
145
146
|
end
|
146
|
-
end
|
147
147
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
156
156
|
|
157
|
-
|
157
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
158
158
|
|
159
|
-
|
159
|
+
return false unless '~' == path[0]
|
160
160
|
|
161
|
-
|
161
|
+
if path.size > 1
|
162
162
|
|
163
|
-
|
164
|
-
|
163
|
+
return '/' == path[1]
|
164
|
+
end
|
165
165
|
|
166
|
-
|
167
|
-
|
166
|
+
true
|
167
|
+
end
|
168
168
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
177
177
|
|
178
|
-
|
178
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
179
179
|
|
180
|
-
|
181
|
-
|
180
|
+
'/' == path[0]
|
181
|
+
end
|
182
|
+
end # module LibPath_Form_Unix_Methods
|
182
183
|
|
183
|
-
|
184
|
+
# @!visibility private
|
185
|
+
def self.extended receiver # :nodoc:
|
184
186
|
|
185
|
-
|
186
|
-
def self.extended receiver # :nodoc:
|
187
|
+
receiver.class_eval do
|
187
188
|
|
188
|
-
|
189
|
+
extend LibPath_Form_Unix_Methods
|
190
|
+
end
|
189
191
|
|
190
|
-
|
192
|
+
$stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
|
191
193
|
end
|
192
194
|
|
193
|
-
|
194
|
-
|
195
|
+
# @!visibility private
|
196
|
+
def self.included receiver # :nodoc:
|
195
197
|
|
196
|
-
|
197
|
-
def self.included receiver # :nodoc:
|
198
|
+
receiver.class_eval do
|
198
199
|
|
199
|
-
|
200
|
+
include LibPath_Form_Unix_Methods
|
201
|
+
end
|
200
202
|
|
201
|
-
|
203
|
+
$stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
|
202
204
|
end
|
203
205
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
extend LibPath_Form_Unix_Methods
|
208
|
-
include LibPath_Form_Unix_Methods
|
206
|
+
extend LibPath_Form_Unix_Methods
|
207
|
+
include LibPath_Form_Unix_Methods
|
209
208
|
|
210
209
|
end # module Unix
|
211
210
|
end # module Form
|