stduritemplate 0.0.39 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/stduritemplate.rb +60 -60
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8efa6481a69bb31c06154ce5f3193acf9c4a4ea1cb36b2c4247180a203d3872
|
4
|
+
data.tar.gz: 490c842eacdedc77dbc711e72c6eb36b8fa8487be15c31793057a5b6716665a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 990ccb2e37e117856cca2bff247fea4fa01bbdeed93c19072fb6254345d6bf4b97f381f61c8d68c2f574058f9e490e4fbacc1cb360f530c16b1e25522a591799
|
7
|
+
data.tar.gz: c724e45e47e788d6060b213a7b9f600bdb5ed8ba86a21a14c06e75ea705eaee67d6eb6bc28c22944259119e378e65ef08db5c07d699af7045d0d3c44bf9a932e
|
data/lib/stduritemplate.rb
CHANGED
@@ -10,8 +10,8 @@ module StdUriTemplate
|
|
10
10
|
# Private implementation
|
11
11
|
private
|
12
12
|
|
13
|
-
module
|
14
|
-
|
13
|
+
module Operator
|
14
|
+
NO_OP = :no_op
|
15
15
|
PLUS = :plus
|
16
16
|
HASH = :hash
|
17
17
|
DOT = :dot
|
@@ -44,33 +44,33 @@ module StdUriTemplate
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.
|
47
|
+
def self.get_operator(c, token, col)
|
48
48
|
case c
|
49
49
|
when '+'
|
50
|
-
|
50
|
+
Operator::PLUS
|
51
51
|
when '#'
|
52
|
-
|
52
|
+
Operator::HASH
|
53
53
|
when '.'
|
54
|
-
|
54
|
+
Operator::DOT
|
55
55
|
when '/'
|
56
|
-
|
56
|
+
Operator::SLASH
|
57
57
|
when ';'
|
58
|
-
|
58
|
+
Operator::SEMICOLON
|
59
59
|
when '?'
|
60
|
-
|
60
|
+
Operator::QUESTION_MARK
|
61
61
|
when '&'
|
62
|
-
|
62
|
+
Operator::AMP
|
63
63
|
else
|
64
64
|
validate_literal(c, col)
|
65
65
|
token << c
|
66
|
-
|
66
|
+
Operator::NO_OP
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
def self.expand_impl(str, substitutions)
|
71
71
|
result = ''
|
72
72
|
token = nil
|
73
|
-
|
73
|
+
operator = nil
|
74
74
|
composite = false
|
75
75
|
max_char_buffer = nil
|
76
76
|
first_token = true
|
@@ -82,10 +82,10 @@ module StdUriTemplate
|
|
82
82
|
first_token = true
|
83
83
|
when '}'
|
84
84
|
if token
|
85
|
-
expanded = expand_token(
|
85
|
+
expanded = expand_token(operator, token, composite, get_max_char(max_char_buffer, i), first_token, substitutions, result, i)
|
86
86
|
first_token = false if expanded && first_token
|
87
87
|
token = nil
|
88
|
-
|
88
|
+
operator = nil
|
89
89
|
composite = false
|
90
90
|
max_char_buffer = nil
|
91
91
|
else
|
@@ -93,7 +93,7 @@ module StdUriTemplate
|
|
93
93
|
end
|
94
94
|
when ','
|
95
95
|
if token
|
96
|
-
expanded = expand_token(
|
96
|
+
expanded = expand_token(operator, token, composite, get_max_char(max_char_buffer, i), first_token, substitutions, result, i)
|
97
97
|
first_token = false if expanded && first_token
|
98
98
|
token = ''
|
99
99
|
composite = false
|
@@ -101,8 +101,8 @@ module StdUriTemplate
|
|
101
101
|
end
|
102
102
|
else
|
103
103
|
if token
|
104
|
-
if
|
105
|
-
|
104
|
+
if operator.nil?
|
105
|
+
operator = get_operator(character, token, i)
|
106
106
|
elsif max_char_buffer
|
107
107
|
if character =~ /\d/
|
108
108
|
max_char_buffer << character
|
@@ -132,59 +132,59 @@ module StdUriTemplate
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
def self.add_prefix(
|
136
|
-
case
|
137
|
-
when
|
135
|
+
def self.add_prefix(op, result)
|
136
|
+
case op
|
137
|
+
when Operator::HASH
|
138
138
|
result << '#'
|
139
|
-
when
|
139
|
+
when Operator::DOT
|
140
140
|
result << '.'
|
141
|
-
when
|
141
|
+
when Operator::SLASH
|
142
142
|
result << '/'
|
143
|
-
when
|
143
|
+
when Operator::SEMICOLON
|
144
144
|
result << ';'
|
145
|
-
when
|
145
|
+
when Operator::QUESTION_MARK
|
146
146
|
result << '?'
|
147
|
-
when
|
147
|
+
when Operator::AMP
|
148
148
|
result << '&'
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
def self.add_separator(
|
153
|
-
case
|
154
|
-
when
|
152
|
+
def self.add_separator(op, result)
|
153
|
+
case op
|
154
|
+
when Operator::DOT
|
155
155
|
result << '.'
|
156
|
-
when
|
156
|
+
when Operator::SLASH
|
157
157
|
result << '/'
|
158
|
-
when
|
158
|
+
when Operator::SEMICOLON
|
159
159
|
result << ';'
|
160
|
-
when
|
160
|
+
when Operator::QUESTION_MARK, Operator::AMP
|
161
161
|
result << '&'
|
162
162
|
else
|
163
163
|
result << ','
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
def self.add_value(
|
168
|
-
case
|
169
|
-
when
|
167
|
+
def self.add_value(op, token, value, result, max_char)
|
168
|
+
case op
|
169
|
+
when Operator::PLUS, Operator::HASH
|
170
170
|
add_expanded_value(value, result, max_char, false)
|
171
|
-
when
|
171
|
+
when Operator::QUESTION_MARK, Operator::AMP
|
172
172
|
result << token + '='
|
173
173
|
add_expanded_value(value, result, max_char, true)
|
174
|
-
when
|
174
|
+
when Operator::SEMICOLON
|
175
175
|
result << token
|
176
176
|
result << '=' unless value.empty?
|
177
177
|
add_expanded_value(value, result, max_char, true)
|
178
|
-
when
|
178
|
+
when Operator::DOT, Operator::SLASH, Operator::NO_OP
|
179
179
|
add_expanded_value(value, result, max_char, true)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
def self.add_value_element(
|
184
|
-
case
|
185
|
-
when
|
183
|
+
def self.add_value_element(op, token, value, result, max_char)
|
184
|
+
case op
|
185
|
+
when Operator::PLUS, Operator::HASH
|
186
186
|
add_expanded_value(value, result, max_char, false)
|
187
|
-
when
|
187
|
+
when Operator::QUESTION_MARK, Operator::AMP, Operator::SEMICOLON, Operator::DOT, Operator::SLASH, Operator::NO_OP
|
188
188
|
add_expanded_value(value, result, max_char, true)
|
189
189
|
end
|
190
190
|
end
|
@@ -284,7 +284,7 @@ module StdUriTemplate
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
def self.expand_token(
|
287
|
+
def self.expand_token(operator, token, composite, max_char, first_token, substitutions, result, col)
|
288
288
|
raise ArgumentError, "Found an empty token at col:#{col}" if token.empty?
|
289
289
|
|
290
290
|
value = substitutions[token]
|
@@ -295,65 +295,65 @@ module StdUriTemplate
|
|
295
295
|
return false if empty?(subst_type, value)
|
296
296
|
|
297
297
|
if first_token
|
298
|
-
add_prefix(
|
298
|
+
add_prefix(operator, result)
|
299
299
|
else
|
300
|
-
add_separator(
|
300
|
+
add_separator(operator, result)
|
301
301
|
end
|
302
302
|
|
303
303
|
case subst_type
|
304
304
|
when SubstitutionType::STRING
|
305
|
-
add_string_value(
|
305
|
+
add_string_value(operator, token, value.to_s, result, max_char)
|
306
306
|
when SubstitutionType::LIST
|
307
|
-
add_list_value(
|
307
|
+
add_list_value(operator, token, value, result, max_char, composite)
|
308
308
|
when SubstitutionType::MAP
|
309
|
-
add_map_value(
|
309
|
+
add_map_value(operator, token, value, result, max_char, composite)
|
310
310
|
end
|
311
311
|
|
312
312
|
true
|
313
313
|
end
|
314
314
|
|
315
|
-
def self.add_string_value(
|
316
|
-
add_value(
|
315
|
+
def self.add_string_value(operator, token, value, result, max_char)
|
316
|
+
add_value(operator, token, value, result, max_char)
|
317
317
|
end
|
318
318
|
|
319
|
-
def self.add_list_value(
|
319
|
+
def self.add_list_value(operator, token, value, result, max_char, composite)
|
320
320
|
first = true
|
321
321
|
value.each do |v|
|
322
322
|
if first
|
323
|
-
add_value(
|
323
|
+
add_value(operator, token, v.to_s, result, max_char)
|
324
324
|
first = false
|
325
325
|
else
|
326
326
|
if composite
|
327
|
-
add_separator(
|
328
|
-
add_value(
|
327
|
+
add_separator(operator, result)
|
328
|
+
add_value(operator, token, v.to_s, result, max_char)
|
329
329
|
else
|
330
330
|
result << ','
|
331
|
-
add_value_element(
|
331
|
+
add_value_element(operator, token, v.to_s, result, max_char)
|
332
332
|
end
|
333
333
|
end
|
334
334
|
end
|
335
335
|
!first
|
336
336
|
end
|
337
337
|
|
338
|
-
def self.add_map_value(
|
338
|
+
def self.add_map_value(operator, token, value, result, max_char, composite)
|
339
339
|
first = true
|
340
340
|
raise ArgumentError, 'Value trimming is not allowed on Maps' if max_char != -1
|
341
341
|
|
342
342
|
value.each do |key, val|
|
343
343
|
if composite
|
344
|
-
add_separator(
|
345
|
-
add_value_element(
|
344
|
+
add_separator(operator, result) unless first
|
345
|
+
add_value_element(operator, token, key.to_s, result, max_char)
|
346
346
|
result << '='
|
347
347
|
else
|
348
348
|
if first
|
349
|
-
add_value(
|
349
|
+
add_value(operator, token, key.to_s, result, max_char)
|
350
350
|
else
|
351
351
|
result << ','
|
352
|
-
add_value_element(
|
352
|
+
add_value_element(operator, token, key.to_s, result, max_char)
|
353
353
|
end
|
354
354
|
result << ','
|
355
355
|
end
|
356
|
-
add_value_element(
|
356
|
+
add_value_element(operator, token, val.to_s, result, max_char)
|
357
357
|
first = false
|
358
358
|
end
|
359
359
|
!first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stduritemplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.40
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Peruffo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: std-uritemplate implementation for Ruby
|
14
14
|
email: andrea.peruffo1982@gmail.com
|