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
@@ -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: 7th 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,105 +44,104 @@
|
|
43
44
|
# ######################################################################## #
|
44
45
|
|
45
46
|
|
46
|
-
|
47
47
|
=begin
|
48
48
|
=end
|
49
49
|
|
50
|
-
module LibPath
|
51
|
-
module Constants
|
52
|
-
module Windows
|
50
|
+
module LibPath
|
51
|
+
module Constants
|
52
|
+
module Windows
|
53
53
|
|
54
|
-
# Module defining instance functions that will be included and extended into
|
55
|
-
# any class or module including/extending module LibPath::Constants::Windows
|
56
|
-
module LibPath_Constants_Windows_Details
|
54
|
+
# Module defining instance functions that will be included and extended into
|
55
|
+
# any class or module including/extending module LibPath::Constants::Windows
|
56
|
+
module LibPath_Constants_Windows_Details
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
# Defines invalid characters
|
59
|
+
module InvalidCharacters
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
# Innately invalid characters
|
62
|
+
module Innate
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
# The list of characters
|
65
|
+
LIST = [
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
"\0",
|
68
|
+
]
|
69
|
+
# The regular expression
|
70
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
71
|
+
end # module Innate
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
# Valid path name separator characters
|
74
|
+
module PathNameSeparators
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
# The list of characters
|
77
|
+
LIST = [
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
"\\",
|
80
|
+
'/',
|
81
|
+
]
|
82
|
+
# The regular expression
|
83
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
84
|
+
end # module PathNameSeparators
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
# Valid path separator characters
|
87
|
+
module PathSeparators
|
88
88
|
|
89
|
-
|
90
|
-
|
89
|
+
# The list of characters
|
90
|
+
LIST = [
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
';',
|
93
|
+
]
|
94
|
+
# The regular expression
|
95
|
+
RE = /[#{LIST.map { |m| Regexp.escape m }.join}]/
|
96
|
+
end # module PathSeparators
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
# Invalid shell characters
|
99
|
+
module Shell
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
# The list of characters
|
102
|
+
LIST = [
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end # module LibPath_Constants_Windows_Details
|
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
|
+
end # module LibPath_Constants_Windows_Details
|
115
115
|
|
116
|
-
# @!visibility private
|
117
|
-
def self.extended receiver # :nodoc:
|
116
|
+
# @!visibility private
|
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
|
-
|
125
|
-
end
|
124
|
+
$stderr.puts "#{receiver} extended by #{LibPath_Constants_Windows_Details}" if $DEBUG
|
125
|
+
end
|
126
126
|
|
127
|
-
# @!visibility private
|
128
|
-
def self.included receiver # :nodoc:
|
127
|
+
# @!visibility private
|
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
|
-
|
136
|
-
end
|
135
|
+
$stderr.puts "#{receiver} included #{LibPath_Constants_Windows_Details}" if $DEBUG
|
136
|
+
end
|
137
137
|
|
138
|
-
extend LibPath_Constants_Windows_Details
|
139
|
-
include LibPath_Constants_Windows_Details
|
138
|
+
extend LibPath_Constants_Windows_Details
|
139
|
+
include LibPath_Constants_Windows_Details
|
140
140
|
|
141
141
|
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,40 @@ 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
|
-
module LibPath # :nodoc:
|
13
|
-
module Constants # :nodoc:
|
14
12
|
|
15
|
-
|
13
|
+
module LibPath
|
14
|
+
module Constants
|
16
15
|
|
17
|
-
|
18
|
-
include ::LibPath::Constants::Windows
|
19
|
-
else
|
16
|
+
if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
extend ::LibPath::Constants::Windows
|
19
|
+
include ::LibPath::Constants::Windows
|
20
|
+
else
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
extend ::LibPath::Constants::Unix
|
23
|
+
include ::LibPath::Constants::Unix
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
# @!visibility private
|
27
|
+
def self.extended receiver # :nodoc:
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
$stderr.puts "#{receiver} extended by #{self}" if $DEBUG
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
# @!visibility private
|
33
|
+
def self.included receiver # :nodoc:
|
36
34
|
|
35
|
+
$stderr.puts "#{receiver} included #{self}" if $DEBUG
|
36
|
+
end
|
37
37
|
end # module Constants
|
38
38
|
end # module LibPath
|
39
39
|
|
40
|
-
# ############################## end of file ############################# #
|
41
40
|
|
41
|
+
# ############################## end of file ############################# #
|
42
42
|
|
@@ -1,46 +1,47 @@
|
|
1
1
|
|
2
|
-
module LibPath
|
2
|
+
module LibPath
|
3
|
+
# @!visibility private
|
3
4
|
module Diagnostics # :nodoc:
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
# @!visibility private
|
7
|
+
def self.check_string_parameter param_value, param_name, **options # :nodoc:
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
case param_value
|
10
|
+
when nil
|
10
11
|
|
11
|
-
|
12
|
+
unless options[:allow_nil]
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
raise ::ArgumentError, "parameter '#{param_name}' may not be nil"
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
;
|
18
|
+
when ::String
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
;
|
21
|
+
else
|
21
22
|
|
22
|
-
|
23
|
+
unless param_value.respond_to?(:to_str)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
raise ::TypeError, "parameter '#{param_name}' must be instance of #{::String} or respond to #to_str()"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
# @!visibility private
|
31
|
+
def self.check_options h, *args, **options # :nodoc:
|
31
32
|
|
32
|
-
|
33
|
+
if known = options[:known] then
|
33
34
|
|
34
|
-
|
35
|
+
h.each_key do |k|
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
raise ::ArgumentError, "unknown key '#{k}'" unless known.include?(k)
|
38
|
+
end
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
end
|
41
42
|
end # module Diagnostics
|
42
43
|
end # module LibPath
|
43
44
|
|
44
|
-
# ############################## end of file ############################# #
|
45
45
|
|
46
|
+
# ############################## end of file ############################# #
|
46
47
|
|
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: 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,34 +45,32 @@
|
|
44
45
|
# ######################################################################## #
|
45
46
|
|
46
47
|
|
47
|
-
|
48
48
|
=begin
|
49
49
|
=end
|
50
50
|
|
51
|
-
module LibPath
|
52
|
-
module Exceptions
|
51
|
+
module LibPath
|
52
|
+
module Exceptions
|
53
53
|
|
54
|
-
# Root exception for all LibPath exceptions
|
55
|
-
#
|
56
|
-
# NOTE: this class is abstract
|
57
|
-
class LibPathBaseException < StandardError
|
54
|
+
# Root exception for all LibPath exceptions
|
55
|
+
#
|
56
|
+
# NOTE: this class is abstract
|
57
|
+
class LibPathBaseException < StandardError
|
58
58
|
|
59
59
|
=begin
|
60
60
|
|
61
|
-
|
61
|
+
# TODO include Xqsr3's WithCause
|
62
62
|
=end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
raise NoMethodError, "private method `new' called for #{self}:Class" if self == LibPathBaseException
|
64
|
+
def self.new *args
|
67
65
|
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
66
|
+
raise NoMethodError, "private method `new' called for #{self}:Class" if self == LibPathBaseException
|
71
67
|
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end # module Exceptions
|
73
72
|
end # module LibPath
|
74
73
|
|
75
|
-
# ############################## end of file ############################# #
|
76
74
|
|
75
|
+
# ############################## end of file ############################# #
|
77
76
|
|
@@ -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: 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,42 +45,41 @@
|
|
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
|
-
module LibPath # :nodoc:
|
54
|
-
module Exceptions # :nodoc:
|
55
53
|
|
56
|
-
|
57
|
-
|
54
|
+
module LibPath
|
55
|
+
module Exceptions
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
# * *Parameters:*
|
62
|
-
# - +name+ (String) The name that is malformed
|
63
|
-
# - +message+ (String) {optional} The message. If +nil+ the message "malformed name '#{name}'" is used
|
64
|
-
def initialize name, message = nil
|
57
|
+
# Exception thrown when a malformed name is encountered
|
58
|
+
class MalformedNameException < LibPathBaseException
|
65
59
|
|
66
|
-
|
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
|
67
66
|
|
68
|
-
|
69
|
-
end
|
67
|
+
unless message
|
70
68
|
|
71
|
-
|
69
|
+
message = "malformed name '#{name}'"
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
end
|
72
|
+
super message
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
74
|
+
@name = name
|
75
|
+
end
|
79
76
|
|
77
|
+
# (String) The name that is malformed
|
78
|
+
attr_reader :name
|
79
|
+
end
|
80
80
|
end # module Exceptions
|
81
81
|
end # module LibPath
|
82
82
|
|
83
|
-
# ############################## end of file ############################# #
|
84
83
|
|
84
|
+
# ############################## end of file ############################# #
|
85
85
|
|
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
|
|