impuri 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ImpURI.rb +517 -0
- data/lib/ImpURI/Array/all_but_first.rb +11 -0
- data/lib/ImpURI/Array/all_but_last.rb +24 -0
- data/lib/ImpURI/Array/blankQ.rb +13 -0
- data/lib/ImpURI/Array/extract_optionsX.rb +14 -0
- data/lib/ImpURI/Array/firstX.rb +10 -0
- data/lib/ImpURI/Array/lastX.rb +10 -0
- data/lib/ImpURI/FalseClass/blankQ.rb +15 -0
- data/lib/ImpURI/Hash/blankQ.rb +13 -0
- data/lib/ImpURI/Hash/x_www_form_urlencode.rb +20 -0
- data/lib/ImpURI/Module/alias_methods.rb +16 -0
- data/lib/ImpURI/NilClass/blankQ.rb +15 -0
- data/lib/ImpURI/Numeric/blankQ.rb +15 -0
- data/lib/ImpURI/Object/blankQ.rb +18 -0
- data/lib/ImpURI/String/blankQ.rb +18 -0
- data/lib/ImpURI/TrueClass/blankQ.rb +15 -0
- data/lib/ImpURI/VERSION.rb +6 -0
- data/lib/ImpURI/_meta/blankQ.rb +13 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40ca40d65673baa8fd1e3e0ce1106e66ab63ca2d9aed70cbab13ace1b8c116db
|
4
|
+
data.tar.gz: 4604c7ea0f54a85b99a17fb9c93d864c911ccc950d3d4f622cf4a8a0edca9b26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6be56f6d68e9d44f190798b7f508e4d86fc4b5f67a15305e20a114c692a4070ef6e79259407e13d468d888dedfa5ccebf63d5ed8a6a4943442fb79e4b924a150
|
7
|
+
data.tar.gz: 0b173b0184b505df469f7183eb1d73cd79b020af261691601b2346e3bc09696d970ee00a6096577fe5d0d78d0c7f1e971ff953e2ea26818f46a344b1bffd948d
|
data/lib/ImpURI.rb
ADDED
@@ -0,0 +1,517 @@
|
|
1
|
+
# ImpURI.rb
|
2
|
+
# ImpURI
|
3
|
+
|
4
|
+
# 20200207
|
5
|
+
# 0.8.0
|
6
|
+
|
7
|
+
# Description: A cleaner and simpler URI and ssh/scp resource parser for Ruby. Though I'm not sure about the simpler bit anymore. It's now over 500 lines you know!
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
10
|
+
|
11
|
+
require '_meta/blankQ'
|
12
|
+
require 'Array/all_but_first'
|
13
|
+
require 'Array/all_but_last'
|
14
|
+
require 'Array/extract_optionsX'
|
15
|
+
require 'Hash/x_www_form_urlencode'
|
16
|
+
require 'Module/alias_methods'
|
17
|
+
|
18
|
+
require 'ImpURI/VERSION'
|
19
|
+
|
20
|
+
class ImpURI
|
21
|
+
|
22
|
+
class SchemeMissingError < RuntimeError; end
|
23
|
+
class ColonPathSeparatorsNotAllowedError < RuntimeError; end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
|
27
|
+
attr_accessor :strict
|
28
|
+
|
29
|
+
def parse(uri, *args)
|
30
|
+
ImpURI.new(uri, *args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def scheme(uri)
|
34
|
+
if has_scheme?(uri)
|
35
|
+
uri.split('://').first
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
alias_methods :protocol, :scheme_name, :scheme
|
41
|
+
|
42
|
+
def userinfo(uri)
|
43
|
+
if has_userinfo?(uri)
|
44
|
+
if all_but_scheme(uri).split('@').size > 1
|
45
|
+
all_but_scheme(uri).split('@').all_but_last.join('@')
|
46
|
+
else
|
47
|
+
all_but_scheme(uri).split('@').first
|
48
|
+
end
|
49
|
+
elsif has_username?(uri)
|
50
|
+
uri.split('@').first
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
alias_methods :credentials, :username_and_password, :user_info, :userinfo
|
56
|
+
|
57
|
+
def username(uri)
|
58
|
+
if has_userinfo?(uri)
|
59
|
+
userinfo(uri).split(':')[0]
|
60
|
+
elsif has_username?(uri)
|
61
|
+
uri.split('@').first
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
alias_methods :user, :username
|
67
|
+
|
68
|
+
def password(uri)
|
69
|
+
if has_userinfo?(uri)
|
70
|
+
userinfo(uri).split(':')[1]
|
71
|
+
else
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
alias_methods :pass, :passwd, :password
|
76
|
+
|
77
|
+
def hostname(uri)
|
78
|
+
hostname_and_port_number(uri).split(':').first
|
79
|
+
end
|
80
|
+
alias_methods :host, :hostname
|
81
|
+
|
82
|
+
def port_number(uri)
|
83
|
+
if has_port_number?(uri)
|
84
|
+
hostname_and_port_number(uri).split(':').last
|
85
|
+
else
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
alias_methods :port, :portnumber, :port_number
|
90
|
+
|
91
|
+
# For the instance method providing compatibility to Ruby's URI.
|
92
|
+
def request_uri(uri)
|
93
|
+
if has_colon_path_separator?(uri)
|
94
|
+
path = hostname_and_path(uri).split(':').all_but_first.join('/')
|
95
|
+
else
|
96
|
+
path = hostname_and_path(uri).split('/').all_but_first.join('/')
|
97
|
+
path.blank? ? nil : '/' + path
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def path(uri)
|
102
|
+
if non_nil_request_uri = request_uri(uri)
|
103
|
+
request_uri = non_nil_request_uri.split('?').first
|
104
|
+
request_uri.blank? ? nil : request_uri
|
105
|
+
else
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def parameter_string(uri)
|
111
|
+
parameter_string = has_parameters?(uri) ? request_uri(uri).split('?').last : nil
|
112
|
+
parameter_string.blank? ? nil : parameter_string
|
113
|
+
end
|
114
|
+
alias_methods :query_string, :parameter_string
|
115
|
+
|
116
|
+
def parameters(uri)
|
117
|
+
if non_nil_parameter_string = parameter_string(uri)
|
118
|
+
parameter_parts = (
|
119
|
+
case parameter_separator(uri)
|
120
|
+
when '&'; non_nil_parameter_string.split('&')
|
121
|
+
when ';'; non_nil_parameter_string.split(';')
|
122
|
+
else [non_nil_parameter_string]
|
123
|
+
end
|
124
|
+
)
|
125
|
+
parameter_parts.inject({}) do |h,pairs|
|
126
|
+
a = pairs.split('=')
|
127
|
+
h[a[0]] = a[1]
|
128
|
+
h
|
129
|
+
end
|
130
|
+
else
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
alias_methods :query, :parameters
|
135
|
+
|
136
|
+
def hostname_and_path(uri)
|
137
|
+
if has_userinfo?(uri) || has_username?(uri)
|
138
|
+
if all_but_scheme(uri).split('@').size > 1
|
139
|
+
all_but_scheme(uri).split('@').all_but_first.join('@')
|
140
|
+
else
|
141
|
+
all_but_scheme(uri).split('@').first
|
142
|
+
end
|
143
|
+
else
|
144
|
+
all_but_scheme(uri)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
alias_methods :host_and_path, :hostname_and_path
|
148
|
+
|
149
|
+
def hostname_and_port_number(uri)
|
150
|
+
if has_colon_path_separator?(uri)
|
151
|
+
hostname_and_path(uri).split(':').all_but_last.join(':')
|
152
|
+
else
|
153
|
+
hostname_and_path(uri).split('/').first
|
154
|
+
end
|
155
|
+
end
|
156
|
+
alias_methods :host_and_port, :host_and_portnumber, :host_and_port_number, :hostname_and_port, :hostname_and_portnumber, :hostname_and_port_number
|
157
|
+
|
158
|
+
def has_userinfo?(uri)
|
159
|
+
if has_scheme?(uri)
|
160
|
+
partial_decomposition = uri.split('//').all_but_first.join.split('/')
|
161
|
+
if partial_decomposition.size > 1
|
162
|
+
next_decomposition = partial_decomposition.all_but_last
|
163
|
+
else
|
164
|
+
next_decomposition = [partial_decomposition.first]
|
165
|
+
end
|
166
|
+
next_decomposition.join('/').match(/@/) ? true : false
|
167
|
+
else
|
168
|
+
uri.match(/.+:.+@/) ? true : false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
alias_methods :credentials?, :username_and_password?, :user_info?, :userinfo?, :has_credentials?, :has_username_and_password?, :has_user_info?, :has_userinfo?
|
172
|
+
|
173
|
+
def has_username?(uri)
|
174
|
+
if has_scheme?(uri)
|
175
|
+
all_but_scheme(uri).scan('@').first ? true : false
|
176
|
+
else
|
177
|
+
uri.scan('@').first ? true : false
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def has_scheme?(uri)
|
182
|
+
uri.match(/^[a-z]*?:\/\//) ? true : false
|
183
|
+
end
|
184
|
+
alias_methods :protocol?, :scheme_name?, :scheme?, :has_protocol?, :has_scheme_name?, :has_scheme?
|
185
|
+
|
186
|
+
def has_colon_path_separator?(uri)
|
187
|
+
hostname_and_path(uri).match(/:/) && !has_port_number?(uri) ? true : false
|
188
|
+
end
|
189
|
+
alias_methods :colon_path_separator?, :uses_colon_path_separator?, :has_colon_path_separator?
|
190
|
+
|
191
|
+
def has_port_number?(uri)
|
192
|
+
hostname_and_path(uri).match(/:\d+/) ? true : false
|
193
|
+
end
|
194
|
+
alias_methods :port?, :portnumber?, :port_number?, :has_port?, :has_portnumber?, :has_port_number?
|
195
|
+
|
196
|
+
def has_parameters?(uri)
|
197
|
+
uri.match(/\?/) ? true : false
|
198
|
+
end
|
199
|
+
alias_methods :has_get_parameters?, :has_parameters?
|
200
|
+
|
201
|
+
def has_semicolon_parameter_separator?(uri)
|
202
|
+
uri.match(/;/) ? true : false
|
203
|
+
end
|
204
|
+
alias_methods :has_semicolon_query_separator?, :has_semicolon_parameter_separator?
|
205
|
+
|
206
|
+
def has_ampersand_parameter_separator?(uri)
|
207
|
+
uri.match(/&/) ? true : false
|
208
|
+
end
|
209
|
+
alias_methods :has_ampersand_query_separator?, :has_ampersand_parameter_separator?
|
210
|
+
|
211
|
+
def parameter_separator(uri)
|
212
|
+
if has_ampersand_parameter_separator?(uri)
|
213
|
+
'&'
|
214
|
+
elsif has_semicolon_parameter_separator?(uri)
|
215
|
+
';'
|
216
|
+
else
|
217
|
+
nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
alias_methods :query_separator, :parameter_separator
|
221
|
+
|
222
|
+
def all_but_scheme(uri)
|
223
|
+
uri.split('://').last
|
224
|
+
end
|
225
|
+
|
226
|
+
def all_but_userinfo(uri)
|
227
|
+
if has_userinfo?(uri)
|
228
|
+
"#{scheme_with_separator(uri)}#{hostname_and_path(uri)}"
|
229
|
+
else
|
230
|
+
hostname_and_path(uri)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def scheme_with_separator(uri)
|
235
|
+
if scheme(uri).blank?
|
236
|
+
''
|
237
|
+
else
|
238
|
+
"#{scheme(uri)}://"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
alias_methods :protocol_with_separator, :scheme_with_separator
|
242
|
+
|
243
|
+
def userinfo_with_separator(uri)
|
244
|
+
if username(uri).blank?
|
245
|
+
''
|
246
|
+
elsif password(uri).blank?
|
247
|
+
"#{username(uri)}@"
|
248
|
+
else
|
249
|
+
"#{username(uri)}:#{password(uri)}@"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
alias_methods :credentials_with_separator, :username_and_password_with_separator, :user_info_with_separator, :userinfo_with_separator
|
253
|
+
|
254
|
+
def hostname_optionally_with_port_number(uri)
|
255
|
+
if port_number(uri).blank?
|
256
|
+
"#{hostname(uri)}"
|
257
|
+
else
|
258
|
+
"#{hostname(uri)}:#{port_number(uri)}"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
alias_methods :hostname_optionally_with_portnumber, :hostname_optionally_with_port_number
|
262
|
+
|
263
|
+
def is_ssh?(uri)
|
264
|
+
!has_scheme?(uri) && has_colon_path_separator?(uri) ? true : false
|
265
|
+
end
|
266
|
+
|
267
|
+
end # class << self
|
268
|
+
|
269
|
+
def initialize(uri, *args)
|
270
|
+
options = args.extract_options!
|
271
|
+
if options[:strict]
|
272
|
+
raise SchemeMissingError if !ImpURI.has_scheme?(uri)
|
273
|
+
raise ColonPathSeparatorsNotAllowedError if ImpURI.has_colon_path_separator?(uri)
|
274
|
+
end
|
275
|
+
@uri = uri
|
276
|
+
end
|
277
|
+
|
278
|
+
# attributes
|
279
|
+
|
280
|
+
def scheme
|
281
|
+
@scheme ||= ImpURI.scheme(@uri)
|
282
|
+
end
|
283
|
+
alias_methods :protocol, :scheme_name, :scheme
|
284
|
+
|
285
|
+
def scheme=(new_scheme)
|
286
|
+
@scheme = new_scheme
|
287
|
+
@uri = to_s
|
288
|
+
end
|
289
|
+
alias_methods :protocol=, :scheme_name=, :scheme=
|
290
|
+
|
291
|
+
def username
|
292
|
+
@username ||= ImpURI.username(@uri)
|
293
|
+
end
|
294
|
+
alias_methods :user, :username
|
295
|
+
|
296
|
+
def username=(new_username)
|
297
|
+
@username = new_username
|
298
|
+
@uri = to_s
|
299
|
+
end
|
300
|
+
alias_methods :user=, :username=
|
301
|
+
|
302
|
+
def password
|
303
|
+
@password ||= ImpURI.password(@uri)
|
304
|
+
end
|
305
|
+
alias_methods :pass, :passwd, :password
|
306
|
+
|
307
|
+
def password=(new_password)
|
308
|
+
@password = new_password
|
309
|
+
@uri = to_s
|
310
|
+
end
|
311
|
+
alias_methods :pass=, :passwd=, :password=
|
312
|
+
|
313
|
+
def hostname
|
314
|
+
@hostname ||= ImpURI.hostname(@uri)
|
315
|
+
end
|
316
|
+
alias_methods :host, :hostname
|
317
|
+
|
318
|
+
def hostname=(new_hostname)
|
319
|
+
@hostname = new_hostname
|
320
|
+
@uri = to_s
|
321
|
+
end
|
322
|
+
alias_methods :host=, :hostname=
|
323
|
+
|
324
|
+
def port_number
|
325
|
+
@port_number ||= ImpURI.port_number(@uri)
|
326
|
+
end
|
327
|
+
alias_methods :port, :portnumber, :port_number
|
328
|
+
|
329
|
+
def port_number=(new_port_number)
|
330
|
+
@port_number = new_port_number
|
331
|
+
@uri = to_s
|
332
|
+
end
|
333
|
+
alias_methods :port=, :portnumber=, :port_number=
|
334
|
+
|
335
|
+
def path
|
336
|
+
@path ||= ImpURI.path(@uri)
|
337
|
+
end
|
338
|
+
|
339
|
+
def path=(new_path)
|
340
|
+
@path = new_path
|
341
|
+
@uri = to_s
|
342
|
+
end
|
343
|
+
|
344
|
+
def parameter_string
|
345
|
+
@parameter_string ||= ImpURI.parameter_string(@uri)
|
346
|
+
end
|
347
|
+
|
348
|
+
def parameter_string=(new_parameter_string)
|
349
|
+
@parameter_string = new_parameter_string
|
350
|
+
@uri = to_s
|
351
|
+
@parameters = ImpURI.parameters(@uri)
|
352
|
+
end
|
353
|
+
|
354
|
+
def parameters
|
355
|
+
@parameters ||= ImpURI.parameters(@uri)
|
356
|
+
end
|
357
|
+
|
358
|
+
def parameters=(new_parameters)
|
359
|
+
@parameters = new_parameters
|
360
|
+
@parameter_string = @parameters.x_www_form_urlencode
|
361
|
+
@uri = to_s
|
362
|
+
end
|
363
|
+
|
364
|
+
# For compatability with Ruby's URI. Not quite a drop-in replacement for most aspects as yet however.
|
365
|
+
# Perhaps it should be in a compatability module and included.
|
366
|
+
def request_uri
|
367
|
+
@request_uri ||= ImpURI.request_uri(@uri)
|
368
|
+
end
|
369
|
+
|
370
|
+
# derived attributes
|
371
|
+
|
372
|
+
def scheme_with_separator
|
373
|
+
if scheme.blank?
|
374
|
+
''
|
375
|
+
else
|
376
|
+
"#{scheme}://"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
alias_methods :protocol_with_separator, :scheme_with_separator
|
380
|
+
|
381
|
+
def userinfo
|
382
|
+
if password
|
383
|
+
"#{username}:#{password}"
|
384
|
+
else
|
385
|
+
"#{username}"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
alias_methods :credentials, :username_and_password, :user_info, :userinfo
|
389
|
+
|
390
|
+
def userinfo_with_separator
|
391
|
+
if username.blank?
|
392
|
+
''
|
393
|
+
elsif password.blank?
|
394
|
+
"#{username}@"
|
395
|
+
else
|
396
|
+
"#{username}:#{password}@"
|
397
|
+
end
|
398
|
+
end
|
399
|
+
alias_methods :credentials_with_separator, :username_and_password_with_separator, :user_info_with_separator, :userinfo_with_separator
|
400
|
+
|
401
|
+
def hostname_optionally_with_port_number
|
402
|
+
if has_port_number?
|
403
|
+
"#{hostname}:#{port_number}"
|
404
|
+
else
|
405
|
+
"#{hostname}"
|
406
|
+
end
|
407
|
+
end
|
408
|
+
alias_methods :hostname_optionally_with_portnumber, :hostname_optionally_with_port_number
|
409
|
+
|
410
|
+
def hostname_and_path
|
411
|
+
if has_colon_path_separator?
|
412
|
+
"#{hostname}:#{path}"
|
413
|
+
else
|
414
|
+
"#{hostname}#{path}"
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
def hostname_and_port_number
|
419
|
+
if has_colon_path_separator?
|
420
|
+
hostname_and_path.split(':').all_but_last.join(':')
|
421
|
+
else
|
422
|
+
hostname_and_path.split('/').first
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
def all_but_scheme
|
427
|
+
if has_colon_path_separator?
|
428
|
+
"#{userinfo_with_separator}#{hostname_optionally_with_port_number}:#{path}"
|
429
|
+
else
|
430
|
+
"#{userinfo_with_separator}#{hostname_optionally_with_port_number}#{path}"
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def to_s
|
435
|
+
if has_parameter_string?
|
436
|
+
"#{scheme_with_separator}#{all_but_scheme}?#{parameter_string}"
|
437
|
+
else
|
438
|
+
"#{scheme_with_separator}#{all_but_scheme}"
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
def to_h
|
443
|
+
{scheme: scheme, username: username, password: password, hostname: hostname, port_number: port_number, path: path, parameter_string: parameter_string}
|
444
|
+
end
|
445
|
+
|
446
|
+
# attribute boolean methods
|
447
|
+
|
448
|
+
def has_scheme?
|
449
|
+
scheme.nil? ? false : true
|
450
|
+
end
|
451
|
+
alias_methods :protocol?, :scheme_name?, :scheme?, :has_protocol?, :has_scheme_name?, :has_scheme?
|
452
|
+
|
453
|
+
def has_username?
|
454
|
+
username.nil? ? false : true
|
455
|
+
end
|
456
|
+
alias_methods :user?, :username?, :has_user?, :has_username?
|
457
|
+
|
458
|
+
def has_password?
|
459
|
+
password.nil? ? false : true
|
460
|
+
end
|
461
|
+
alias_methods :pass?, :passwd?, :password?, :has_pass?, :has_passwd?, :has_password?
|
462
|
+
|
463
|
+
def has_hostname?
|
464
|
+
hostname.nil? ? false : true
|
465
|
+
end
|
466
|
+
alias_methods :host?, :hostname?, :has_host?, :has_hostname?
|
467
|
+
|
468
|
+
def has_port_number?
|
469
|
+
port_number.nil? ? false : true
|
470
|
+
end
|
471
|
+
alias_methods :port?, :portnumber?, :port_number?, :has_port?, :has_portnumber?, :has_port_number?
|
472
|
+
|
473
|
+
def has_path?
|
474
|
+
path.nil? ? false : true
|
475
|
+
end
|
476
|
+
alias_methods :path?, :has_path?
|
477
|
+
|
478
|
+
def has_parameter_string?
|
479
|
+
parameter_string.nil? ? false : true
|
480
|
+
end
|
481
|
+
alias_methods :parameter_string?, :has_get_parameter_string?, :has_parameter_string?
|
482
|
+
|
483
|
+
def has_parameters?
|
484
|
+
parameters.nil? ? false : true
|
485
|
+
end
|
486
|
+
alias_methods :parameters?, :has_get_parameters?, :has_parameters?
|
487
|
+
|
488
|
+
# derived attribute boolean methods
|
489
|
+
|
490
|
+
def has_userinfo?
|
491
|
+
ImpURI.has_userinfo?(@uri)
|
492
|
+
end
|
493
|
+
alias_methods :credentials?, :username_and_password?, :user_info?, :userinfo?, :has_credentials?, :has_username_and_password?, :has_user_info?, :has_userinfo?
|
494
|
+
|
495
|
+
def has_colon_path_separator?
|
496
|
+
ImpURI.has_colon_path_separator?(@uri)
|
497
|
+
end
|
498
|
+
alias_methods :colon_path_separator?, :uses_colon_path_separator?, :has_colon_path_separator?
|
499
|
+
|
500
|
+
def has_semicolon_parameter_separator?
|
501
|
+
ImpURI.has_semicolon_parameter_separator?(@uri)
|
502
|
+
end
|
503
|
+
alias_methods :semicolon_query_separator?, :semicolon_parameter_separator?, :has_semicolon_parameter_separator?
|
504
|
+
alias_methods :uses_semicolon_query_separator?, :uses_semicolon_parameter_separator?, :has_semicolon_parameter_separator?
|
505
|
+
alias_methods :has_semicolon_query_separator?, :has_semicolon_parameter_separator?
|
506
|
+
|
507
|
+
def has_ampersand_parameter_separator?
|
508
|
+
ImpURI.has_ampersand_parameter_separator?(@uri)
|
509
|
+
end
|
510
|
+
alias_methods :has_ampersand_query_separator?, :has_ampersand_parameter_separator?
|
511
|
+
|
512
|
+
def is_ssh?
|
513
|
+
ImpURI.is_ssh?(to_s)
|
514
|
+
end
|
515
|
+
alias_methods :ssh?, :is_ssh?
|
516
|
+
|
517
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Array#all_but_last
|
2
|
+
|
3
|
+
# 20080831
|
4
|
+
# 0.1.0
|
5
|
+
|
6
|
+
# Description: This returns a copy of the receiving array with the last element removed.
|
7
|
+
|
8
|
+
# Changes since 0.0:
|
9
|
+
# 1. I've added require 'Array/lastX', since I think it is reasonable that each file should load its own dependencies.
|
10
|
+
|
11
|
+
# Todo:
|
12
|
+
# 1. Conditionally do the require depending on whether the method already exists on Array and/or on whether rubylib has been defined elsewhere, since the require will fail in either case; and if rubylib is available, but this method isn't.
|
13
|
+
|
14
|
+
require 'Array/lastX'
|
15
|
+
|
16
|
+
class Array
|
17
|
+
|
18
|
+
def all_but_last
|
19
|
+
d = self.dup
|
20
|
+
d.last!
|
21
|
+
d
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Hash/x_www_form_urlencode.rb
|
2
|
+
# Hash#x_www_form_urlencode
|
3
|
+
|
4
|
+
# 20130310
|
5
|
+
# 0.0.0
|
6
|
+
|
7
|
+
# Notes: Extracted from MtGox library.
|
8
|
+
|
9
|
+
# Todo:
|
10
|
+
# 1. I should separate out the functionality for adding '+' characters so as it can do both styles of encoding. That way I could reuse the existing Hash/to_parameter_string method as well...
|
11
|
+
|
12
|
+
require 'String/url_encode'
|
13
|
+
|
14
|
+
class Hash
|
15
|
+
|
16
|
+
def x_www_form_urlencode(joiner = '&')
|
17
|
+
inject([]){|a,e| a << "#{e.first.to_s.url_encode.gsub(/ /, '+')}=#{e.last.to_s.url_encode.gsub(/ /, '+')}" unless e.last.nil?; a}.join(joiner)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Module#alias_methods
|
2
|
+
|
3
|
+
# 20080831
|
4
|
+
# 0.0.0
|
5
|
+
|
6
|
+
# Description: I have a penchance for having multiple method names and having line after line of alias_method calls is kinda ugly.
|
7
|
+
|
8
|
+
require 'Array/all_but_last'
|
9
|
+
|
10
|
+
class Module
|
11
|
+
|
12
|
+
def alias_methods(*args)
|
13
|
+
args.all_but_last.each{|e| alias_method e.to_sym, args.last.to_sym}
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Object#blankQ
|
2
|
+
# Object#blank?
|
3
|
+
|
4
|
+
# 2010.04.04
|
5
|
+
# 0.0.1
|
6
|
+
|
7
|
+
# History: Stolen wholesale from a recent version of ActiveSupport.
|
8
|
+
|
9
|
+
# Changes:
|
10
|
+
# 1. Now using a more recent version from ActiveSupport. This more recent version from ActiveSupport is likely more efficient and slightly more succinct.
|
11
|
+
|
12
|
+
class Object
|
13
|
+
|
14
|
+
def blank?
|
15
|
+
respond_to?(:empty?) ? empty? : !self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# String#blank?
|
2
|
+
# String#blankQ
|
3
|
+
|
4
|
+
# 2010.04.04
|
5
|
+
# 0.0.1
|
6
|
+
|
7
|
+
# History: Stolen wholesale from a recent version of ActiveSupport.
|
8
|
+
|
9
|
+
# Changes:
|
10
|
+
# 1. Now using a more recent version from ActiveSupport. This more recent version from ActiveSupport is likely more efficient and slightly more succinct.
|
11
|
+
|
12
|
+
class String
|
13
|
+
|
14
|
+
def blank?
|
15
|
+
self !~ /\S/
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# _meta/blankQ
|
2
|
+
|
3
|
+
# 2010.04.04
|
4
|
+
# 0.0.0
|
5
|
+
|
6
|
+
require 'Array/blankQ'
|
7
|
+
require 'FalseClass/blankQ'
|
8
|
+
require 'Hash/blankQ'
|
9
|
+
require 'NilClass/blankQ'
|
10
|
+
require 'Numeric/blankQ'
|
11
|
+
require 'Object/blankQ'
|
12
|
+
require 'String/blankQ'
|
13
|
+
require 'TrueClass/blankQ'
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: impuri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- thoran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A cleaner and simpler URI and ssh/scp resource parser for Ruby. Though
|
14
|
+
I'm not sure about the simpler bit anymore. It's now over 500 lines you know!
|
15
|
+
email: code@thoran.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ImpURI.rb
|
21
|
+
- lib/ImpURI/Array/all_but_first.rb
|
22
|
+
- lib/ImpURI/Array/all_but_last.rb
|
23
|
+
- lib/ImpURI/Array/blankQ.rb
|
24
|
+
- lib/ImpURI/Array/extract_optionsX.rb
|
25
|
+
- lib/ImpURI/Array/firstX.rb
|
26
|
+
- lib/ImpURI/Array/lastX.rb
|
27
|
+
- lib/ImpURI/FalseClass/blankQ.rb
|
28
|
+
- lib/ImpURI/Hash/blankQ.rb
|
29
|
+
- lib/ImpURI/Hash/x_www_form_urlencode.rb
|
30
|
+
- lib/ImpURI/Module/alias_methods.rb
|
31
|
+
- lib/ImpURI/NilClass/blankQ.rb
|
32
|
+
- lib/ImpURI/Numeric/blankQ.rb
|
33
|
+
- lib/ImpURI/Object/blankQ.rb
|
34
|
+
- lib/ImpURI/String/blankQ.rb
|
35
|
+
- lib/ImpURI/TrueClass/blankQ.rb
|
36
|
+
- lib/ImpURI/VERSION.rb
|
37
|
+
- lib/ImpURI/_meta/blankQ.rb
|
38
|
+
homepage: http://github.com/thoran/ImpURI
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.8.6
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.1.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: A cleaner and simpler URI and ssh/scp resource parser for Ruby.
|
61
|
+
test_files: []
|