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.
@@ -5,7 +5,7 @@
5
5
  # Purpose: LibPath::Form::Unix module
6
6
  #
7
7
  # Created: 8th January 2019
8
- # Updated: 6th April 2024
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
- module LibPath # :nodoc:
56
- module Form # :nodoc:
57
- module Unix # :nodoc:
52
+ =begin
53
+ =end
58
54
 
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
55
+ module LibPath
56
+ module Form
57
+ module Unix
62
58
 
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
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
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
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
- return nil if path.nil? || path.empty?
72
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
75
73
 
76
- return :homed if path_is_homed? path
74
+ return nil if path.nil? || path.empty?
77
75
 
78
- return :absolute if path_is_absolute? path
76
+ return :homed if path_is_homed? path
79
77
 
80
- :relative
81
- end
78
+ return :absolute if path_is_absolute? path
79
+
80
+ :relative
81
+ end
82
82
 
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
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
- _Constants = ::LibPath::Constants::Unix
96
+ _Constants = ::LibPath::Constants::Unix
97
97
 
98
- if name
98
+ if name
99
99
 
100
- if options[:reject_path_name_separators]
100
+ if options[:reject_path_name_separators]
101
101
 
102
- return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
103
- end
102
+ return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
103
+ end
104
104
 
105
- if options[:reject_path_separators]
105
+ if options[:reject_path_separators]
106
106
 
107
- return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
108
- end
107
+ return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
108
+ end
109
109
 
110
- if options[:reject_shell_characters]
110
+ if options[:reject_shell_characters]
111
111
 
112
- return true if name =~ _Constants::InvalidCharacters::Shell::RE
113
- end
112
+ return true if name =~ _Constants::InvalidCharacters::Shell::RE
113
+ end
114
114
 
115
- return true if name =~ _Constants::InvalidCharacters::Innate::RE
115
+ return true if name =~ _Constants::InvalidCharacters::Innate::RE
116
116
 
117
- false
118
- else
117
+ false
118
+ else
119
119
 
120
- true
120
+ true
121
+ end
121
122
  end
122
- end
123
123
 
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
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
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
133
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
134
134
 
135
- case path[0]
136
- when '/'
135
+ case path[0]
136
+ when '/'
137
137
 
138
- true
139
- when '~'
138
+ true
139
+ when '~'
140
140
 
141
- 1 == path.size || '/' == path[1]
142
- else
141
+ 1 == path.size || '/' == path[1]
142
+ else
143
143
 
144
- false
144
+ false
145
+ end
145
146
  end
146
- end
147
147
 
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
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
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
157
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
158
158
 
159
- return false unless '~' == path[0]
159
+ return false unless '~' == path[0]
160
160
 
161
- if path.size > 1
161
+ if path.size > 1
162
162
 
163
- return '/' == path[1]
164
- end
163
+ return '/' == path[1]
164
+ end
165
165
 
166
- true
167
- end
166
+ true
167
+ end
168
168
 
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
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
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
178
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
179
179
 
180
- '/' == path[0]
181
- end
180
+ '/' == path[0]
181
+ end
182
+ end # module LibPath_Form_Unix_Methods
182
183
 
183
- end # module LibPath_Form_Unix_Methods
184
+ # @!visibility private
185
+ def self.extended receiver # :nodoc:
184
186
 
185
- # @!visibility private
186
- def self.extended receiver # :nodoc:
187
+ receiver.class_eval do
187
188
 
188
- receiver.class_eval do
189
+ extend LibPath_Form_Unix_Methods
190
+ end
189
191
 
190
- extend LibPath_Form_Unix_Methods
192
+ $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
191
193
  end
192
194
 
193
- $stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
194
- end
195
+ # @!visibility private
196
+ def self.included receiver # :nodoc:
195
197
 
196
- # @!visibility private
197
- def self.included receiver # :nodoc:
198
+ receiver.class_eval do
198
199
 
199
- receiver.class_eval do
200
+ include LibPath_Form_Unix_Methods
201
+ end
200
202
 
201
- include LibPath_Form_Unix_Methods
203
+ $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
202
204
  end
203
205
 
204
- $stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
205
- end
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