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