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.
- 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 +71 -71
- data/lib/libpath/constants/windows.rb +72 -72
- data/lib/libpath/constants.rb +18 -19
- data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +104 -103
- data/lib/libpath/form/windows.rb +200 -199
- data/lib/libpath/form.rb +18 -18
- data/lib/libpath/internal_/array.rb +53 -53
- data/lib/libpath/internal_/platform.rb +24 -24
- data/lib/libpath/internal_/string.rb +18 -18
- data/lib/libpath/internal_/unix/form.rb +116 -116
- data/lib/libpath/internal_/windows/drive.rb +59 -59
- data/lib/libpath/internal_/windows/form.rb +189 -189
- data/lib/libpath/libpath.rb +3 -0
- data/lib/libpath/path/unix.rb +114 -112
- data/lib/libpath/path/windows.rb +120 -118
- data/lib/libpath/path.rb +18 -20
- data/lib/libpath/util/unix.rb +258 -258
- data/lib/libpath/util/windows.rb +400 -400
- data/lib/libpath/util.rb +18 -19
- data/lib/libpath/version.rb +23 -24
- 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
@@ -1,15 +1,16 @@
|
|
1
1
|
# ######################################################################## #
|
2
|
-
# File:
|
2
|
+
# File: libpath/constants/windows.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: LibPath::Constants::Windows module
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 29th January 2019
|
7
|
+
# Updated: 6th April 2024
|
8
8
|
#
|
9
|
-
# Home:
|
9
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
10
10
|
#
|
11
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
12
12
|
#
|
13
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
13
14
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
14
15
|
# All rights reserved.
|
15
16
|
#
|
@@ -43,7 +44,6 @@
|
|
43
44
|
# ######################################################################## #
|
44
45
|
|
45
46
|
|
46
|
-
|
47
47
|
=begin
|
48
48
|
=end
|
49
49
|
|
@@ -55,84 +55,84 @@ module Windows # :nodoc:
|
|
55
55
|
# any class or module including/extending module LibPath::Constants::Windows
|
56
56
|
module LibPath_Constants_Windows_Details
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
58
|
+
# Defines invalid characters
|
59
|
+
module InvalidCharacters
|
60
|
+
|
61
|
+
# Innately invalid characters
|
62
|
+
module Innate
|
63
|
+
|
64
|
+
# The list of characters
|
65
|
+
LIST = [
|
66
|
+
|
67
|
+
"\0",
|
68
|
+
]
|
69
|
+
# The regular expression
|
70
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
71
|
+
end # module Innate
|
72
|
+
|
73
|
+
# Valid path name separator characters
|
74
|
+
module PathNameSeparators
|
75
|
+
|
76
|
+
# The list of characters
|
77
|
+
LIST = [
|
78
|
+
|
79
|
+
"\\",
|
80
|
+
'/',
|
81
|
+
]
|
82
|
+
# The regular expression
|
83
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
84
|
+
end # module PathNameSeparators
|
85
|
+
|
86
|
+
# Valid path separator characters
|
87
|
+
module PathSeparators
|
88
|
+
|
89
|
+
# The list of characters
|
90
|
+
LIST = [
|
91
|
+
|
92
|
+
';',
|
93
|
+
]
|
94
|
+
# The regular expression
|
95
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
96
|
+
end # module PathSeparators
|
97
|
+
|
98
|
+
# Invalid shell characters
|
99
|
+
module Shell
|
100
|
+
|
101
|
+
# The list of characters
|
102
|
+
LIST = [
|
103
|
+
|
104
|
+
'*',
|
105
|
+
'<',
|
106
|
+
'>',
|
107
|
+
'?',
|
108
|
+
'|',
|
109
|
+
]
|
110
|
+
# The regular expression
|
111
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
112
|
+
end # module Shell
|
113
|
+
end # module InvalidCharacters
|
114
114
|
end # module LibPath_Constants_Windows_Details
|
115
115
|
|
116
116
|
# @!visibility private
|
117
117
|
def self.extended receiver # :nodoc:
|
118
118
|
|
119
|
-
|
119
|
+
receiver.class_eval do
|
120
120
|
|
121
|
-
|
122
|
-
|
121
|
+
extend LibPath_Constants_Windows_Details
|
122
|
+
end
|
123
123
|
|
124
|
-
|
124
|
+
$stderr.puts "#{receiver} extended by #{LibPath_Constants_Windows_Details}" if $DEBUG
|
125
125
|
end
|
126
126
|
|
127
127
|
# @!visibility private
|
128
128
|
def self.included receiver # :nodoc:
|
129
129
|
|
130
|
-
|
130
|
+
receiver.class_eval do
|
131
131
|
|
132
|
-
|
133
|
-
|
132
|
+
include LibPath_Constants_Windows_Details
|
133
|
+
end
|
134
134
|
|
135
|
-
|
135
|
+
$stderr.puts "#{receiver} included #{LibPath_Constants_Windows_Details}" if $DEBUG
|
136
136
|
end
|
137
137
|
|
138
138
|
extend LibPath_Constants_Windows_Details
|
@@ -142,6 +142,6 @@ end # module Windows
|
|
142
142
|
end # module Constants
|
143
143
|
end # module LibPath
|
144
144
|
|
145
|
-
# ############################## end of file ############################# #
|
146
145
|
|
146
|
+
# ############################## end of file ############################# #
|
147
147
|
|
data/lib/libpath/constants.rb
CHANGED
@@ -3,40 +3,39 @@ require 'libpath/internal_/platform'
|
|
3
3
|
|
4
4
|
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
5
5
|
|
6
|
-
|
6
|
+
require 'libpath/constants/windows'
|
7
7
|
else
|
8
8
|
|
9
|
-
|
9
|
+
require 'libpath/constants/unix'
|
10
10
|
end
|
11
11
|
|
12
12
|
module LibPath # :nodoc:
|
13
13
|
module Constants # :nodoc:
|
14
14
|
|
15
|
-
|
15
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
extend ::LibPath::Constants::Windows
|
18
|
+
include ::LibPath::Constants::Windows
|
19
|
+
else
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
extend ::LibPath::Constants::Unix
|
22
|
+
include ::LibPath::Constants::Unix
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# @!visibility private
|
26
|
+
def self.extended receiver # :nodoc:
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
$stderr.puts "#{receiver} extended by #{self}" if $DEBUG
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
$stderr.puts "#{receiver} included #{self}" if $DEBUG
|
35
|
-
end
|
31
|
+
# @!visibility private
|
32
|
+
def self.included receiver # :nodoc:
|
36
33
|
|
34
|
+
$stderr.puts "#{receiver} included #{self}" if $DEBUG
|
35
|
+
end
|
37
36
|
end # module Constants
|
38
37
|
end # module LibPath
|
39
38
|
|
40
|
-
# ############################## end of file ############################# #
|
41
39
|
|
40
|
+
# ############################## end of file ############################# #
|
42
41
|
|
@@ -2,45 +2,45 @@
|
|
2
2
|
module LibPath # :nodoc:
|
3
3
|
module Diagnostics # :nodoc:
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# @!visibility private
|
6
|
+
def self.check_string_parameter param_value, param_name, **options # :nodoc:
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
case param_value
|
9
|
+
when nil
|
10
10
|
|
11
|
-
|
11
|
+
unless options[:allow_nil]
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
raise ::ArgumentError, "parameter '#{param_name}' may not be nil"
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
;
|
17
|
+
when ::String
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
;
|
20
|
+
else
|
21
21
|
|
22
|
-
|
22
|
+
unless param_value.respond_to?(:to_str)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
raise ::TypeError, "parameter '#{param_name}' must be instance of #{::String} or respond to #to_str()"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
# @!visibility private
|
30
|
+
def self.check_options h, *args, **options # :nodoc:
|
31
31
|
|
32
|
-
|
32
|
+
if known = options[:known] then
|
33
33
|
|
34
|
-
|
34
|
+
h.each_key do |k|
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
raise ::ArgumentError, "unknown key '#{k}'" unless known.include?(k)
|
37
|
+
end
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
end
|
41
41
|
end # module Diagnostics
|
42
42
|
end # module LibPath
|
43
43
|
|
44
|
-
# ############################## end of file ############################# #
|
45
44
|
|
45
|
+
# ############################## end of file ############################# #
|
46
46
|
|
data/lib/libpath/diagnostics.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: libpath/exceptions/libpath_base_exception.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: LibPathBaseException class
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 30th January 2019
|
8
|
+
# Updated: 6th 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,7 +45,6 @@
|
|
44
45
|
# ######################################################################## #
|
45
46
|
|
46
47
|
|
47
|
-
|
48
48
|
=begin
|
49
49
|
=end
|
50
50
|
|
@@ -58,20 +58,20 @@ class LibPathBaseException < StandardError
|
|
58
58
|
|
59
59
|
=begin
|
60
60
|
|
61
|
-
|
61
|
+
# TODO include Xqsr3's WithCause
|
62
62
|
=end
|
63
63
|
|
64
|
-
|
64
|
+
def self.new *args
|
65
65
|
|
66
|
-
|
66
|
+
raise NoMethodError, "private method `new' called for #{self}:Class" if self == LibPathBaseException
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
super
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|
72
72
|
end # module Exceptions
|
73
73
|
end # module LibPath
|
74
74
|
|
75
|
-
# ############################## end of file ############################# #
|
76
75
|
|
76
|
+
# ############################## end of file ############################# #
|
77
77
|
|
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: libpath/exceptions/malformed_name_exception.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: MalformedNameException class
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 30th January 2019
|
8
|
+
# Updated: 6th 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,42 +45,42 @@
|
|
44
45
|
# ######################################################################## #
|
45
46
|
|
46
47
|
|
47
|
-
|
48
48
|
=begin
|
49
49
|
=end
|
50
50
|
|
51
51
|
require 'libpath/exceptions/libpath_base_exception'
|
52
52
|
|
53
|
+
|
53
54
|
module LibPath # :nodoc:
|
54
55
|
module Exceptions # :nodoc:
|
55
56
|
|
56
57
|
# Exception thrown when a malformed name is encountered
|
57
58
|
class MalformedNameException < LibPathBaseException
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
# Initialises an instance from the given +name+ and optional +message+
|
61
|
+
#
|
62
|
+
# * *Parameters:*
|
63
|
+
# - +name+ (String) The name that is malformed
|
64
|
+
# - +message+ (String) {optional} The message. If +nil+ the message "malformed name '#{name}'" is used
|
65
|
+
def initialize name, message = nil
|
65
66
|
|
66
|
-
|
67
|
+
unless message
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
message = "malformed name '#{name}'"
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
+
super message
|
72
73
|
|
73
|
-
|
74
|
-
|
74
|
+
@name = name
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
# (String) The name that is malformed
|
78
|
+
attr_reader :name
|
78
79
|
end
|
79
80
|
|
80
81
|
end # module Exceptions
|
81
82
|
end # module LibPath
|
82
83
|
|
83
|
-
# ############################## end of file ############################# #
|
84
84
|
|
85
|
+
# ############################## end of file ############################# #
|
85
86
|
|
data/lib/libpath/exceptions.rb
CHANGED
@@ -2,6 +2,6 @@
|
|
2
2
|
require 'libpath/exceptions/libpath_base_exception'
|
3
3
|
require 'libpath/exceptions/malformed_name_exception'
|
4
4
|
|
5
|
-
# ############################## end of file ############################# #
|
6
5
|
|
6
|
+
# ############################## end of file ############################# #
|
7
7
|
|