jmespath 1.6.1 → 1.6.2
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/VERSION +1 -1
- data/bin/jmespath.rb +12 -0
- data/lib/jmespath/caching_parser.rb +1 -2
- data/lib/jmespath/errors.rb +2 -2
- data/lib/jmespath/lexer.rb +19 -22
- data/lib/jmespath/nodes/and.rb +1 -2
- data/lib/jmespath/nodes/comparator.rb +6 -22
- data/lib/jmespath/nodes/condition.rb +3 -2
- data/lib/jmespath/nodes/current.rb +1 -0
- data/lib/jmespath/nodes/expression.rb +2 -2
- data/lib/jmespath/nodes/field.rb +3 -7
- data/lib/jmespath/nodes/flatten.rb +1 -2
- data/lib/jmespath/nodes/function.rb +64 -68
- data/lib/jmespath/nodes/index.rb +1 -0
- data/lib/jmespath/nodes/literal.rb +2 -1
- data/lib/jmespath/nodes/multi_select_hash.rb +1 -0
- data/lib/jmespath/nodes/multi_select_list.rb +1 -0
- data/lib/jmespath/nodes/not.rb +1 -2
- data/lib/jmespath/nodes/or.rb +1 -0
- data/lib/jmespath/nodes/pipe.rb +1 -0
- data/lib/jmespath/nodes/projection.rb +4 -11
- data/lib/jmespath/nodes/slice.rb +13 -18
- data/lib/jmespath/nodes/subexpression.rb +1 -0
- data/lib/jmespath/nodes.rb +3 -4
- data/lib/jmespath/parser.rb +24 -29
- data/lib/jmespath/runtime.rb +1 -2
- data/lib/jmespath/token.rb +3 -4
- data/lib/jmespath/token_stream.rb +4 -5
- data/lib/jmespath/util.rb +5 -5
- data/lib/jmespath/version.rb +1 -0
- data/lib/jmespath.rb +6 -8
- metadata +6 -4
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
4
5
|
class Function < Node
|
5
|
-
|
6
6
|
FUNCTIONS = {}
|
7
7
|
|
8
8
|
def initialize(children, options = {})
|
@@ -38,12 +38,10 @@ module JMESPath
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def maybe_raise(error_type, message)
|
41
|
-
unless @disable_visit_errors
|
42
|
-
raise error_type, message
|
43
|
-
end
|
41
|
+
raise error_type, message unless @disable_visit_errors
|
44
42
|
end
|
45
43
|
|
46
|
-
def call(
|
44
|
+
def call(_args)
|
47
45
|
nil
|
48
46
|
end
|
49
47
|
end
|
@@ -54,7 +52,7 @@ module JMESPath
|
|
54
52
|
STRING_TYPE
|
55
53
|
elsif value == true || value == false
|
56
54
|
BOOLEAN_TYPE
|
57
|
-
elsif value
|
55
|
+
elsif value.nil?
|
58
56
|
NULL_TYPE
|
59
57
|
elsif value.is_a?(Numeric)
|
60
58
|
NUMBER_TYPE
|
@@ -82,7 +80,7 @@ module JMESPath
|
|
82
80
|
NULL_TYPE => 'null',
|
83
81
|
NUMBER_TYPE => 'number',
|
84
82
|
OBJECT_TYPE => 'object',
|
85
|
-
STRING_TYPE => 'string'
|
83
|
+
STRING_TYPE => 'string'
|
86
84
|
}.freeze
|
87
85
|
end
|
88
86
|
|
@@ -93,12 +91,12 @@ module JMESPath
|
|
93
91
|
if args.count == 1
|
94
92
|
value = args.first
|
95
93
|
else
|
96
|
-
return maybe_raise Errors::InvalidArityError,
|
94
|
+
return maybe_raise Errors::InvalidArityError, 'function abs() expects one argument'
|
97
95
|
end
|
98
96
|
if Numeric === value
|
99
97
|
value.abs
|
100
98
|
else
|
101
|
-
return maybe_raise Errors::InvalidTypeError,
|
99
|
+
return maybe_raise Errors::InvalidTypeError, 'function abs() expects a number'
|
102
100
|
end
|
103
101
|
end
|
104
102
|
end
|
@@ -110,20 +108,20 @@ module JMESPath
|
|
110
108
|
if args.count == 1
|
111
109
|
values = args.first
|
112
110
|
else
|
113
|
-
return maybe_raise Errors::InvalidArityError,
|
111
|
+
return maybe_raise Errors::InvalidArityError, 'function avg() expects one argument'
|
114
112
|
end
|
115
113
|
if values.respond_to?(:to_ary)
|
116
114
|
values = values.to_ary
|
117
115
|
return nil if values.empty?
|
118
|
-
values.inject(0) do |total,n|
|
116
|
+
values.inject(0) do |total, n|
|
119
117
|
if Numeric === n
|
120
118
|
total + n
|
121
119
|
else
|
122
|
-
return maybe_raise Errors::InvalidTypeError,
|
120
|
+
return maybe_raise Errors::InvalidTypeError, 'function avg() expects numeric values'
|
123
121
|
end
|
124
122
|
end / values.size.to_f
|
125
123
|
else
|
126
|
-
return maybe_raise Errors::InvalidTypeError,
|
124
|
+
return maybe_raise Errors::InvalidTypeError, 'function avg() expects a number'
|
127
125
|
end
|
128
126
|
end
|
129
127
|
end
|
@@ -135,12 +133,12 @@ module JMESPath
|
|
135
133
|
if args.count == 1
|
136
134
|
value = args.first
|
137
135
|
else
|
138
|
-
return maybe_raise Errors::InvalidArityError,
|
136
|
+
return maybe_raise Errors::InvalidArityError, 'function ceil() expects one argument'
|
139
137
|
end
|
140
138
|
if Numeric === value
|
141
139
|
value.ceil
|
142
140
|
else
|
143
|
-
return maybe_raise Errors::InvalidTypeError,
|
141
|
+
return maybe_raise Errors::InvalidTypeError, 'function ceil() expects a numeric value'
|
144
142
|
end
|
145
143
|
end
|
146
144
|
end
|
@@ -157,10 +155,10 @@ module JMESPath
|
|
157
155
|
elsif haystack.respond_to?(:to_ary)
|
158
156
|
haystack.to_ary.any? { |e| Util.as_json(e) == needle }
|
159
157
|
else
|
160
|
-
return maybe_raise Errors::InvalidTypeError,
|
158
|
+
return maybe_raise Errors::InvalidTypeError, 'contains expects 2nd arg to be a list'
|
161
159
|
end
|
162
160
|
else
|
163
|
-
return maybe_raise Errors::InvalidArityError,
|
161
|
+
return maybe_raise Errors::InvalidArityError, 'function contains() expects 2 arguments'
|
164
162
|
end
|
165
163
|
end
|
166
164
|
end
|
@@ -172,12 +170,12 @@ module JMESPath
|
|
172
170
|
if args.count == 1
|
173
171
|
value = args.first
|
174
172
|
else
|
175
|
-
return maybe_raise Errors::InvalidArityError,
|
173
|
+
return maybe_raise Errors::InvalidArityError, 'function floor() expects one argument'
|
176
174
|
end
|
177
175
|
if Numeric === value
|
178
176
|
value.floor
|
179
177
|
else
|
180
|
-
return maybe_raise Errors::InvalidTypeError,
|
178
|
+
return maybe_raise Errors::InvalidTypeError, 'function floor() expects a numeric value'
|
181
179
|
end
|
182
180
|
end
|
183
181
|
end
|
@@ -189,7 +187,7 @@ module JMESPath
|
|
189
187
|
if args.count == 1
|
190
188
|
value = args.first
|
191
189
|
else
|
192
|
-
return maybe_raise Errors::InvalidArityError,
|
190
|
+
return maybe_raise Errors::InvalidArityError, 'function length() expects one argument'
|
193
191
|
end
|
194
192
|
if value.respond_to?(:to_hash)
|
195
193
|
value.to_hash.size
|
@@ -198,32 +196,30 @@ module JMESPath
|
|
198
196
|
elsif value.respond_to?(:to_str)
|
199
197
|
value.to_str.size
|
200
198
|
else
|
201
|
-
return maybe_raise Errors::InvalidTypeError,
|
199
|
+
return maybe_raise Errors::InvalidTypeError, 'function length() expects string, array or object'
|
202
200
|
end
|
203
201
|
end
|
204
202
|
end
|
205
203
|
|
206
204
|
class Map < Function
|
207
|
-
|
208
205
|
FUNCTIONS['map'] = self
|
209
206
|
|
210
207
|
def call(args)
|
211
208
|
if args.count != 2
|
212
|
-
return maybe_raise Errors::InvalidArityError,
|
209
|
+
return maybe_raise Errors::InvalidArityError, 'function map() expects two arguments'
|
213
210
|
end
|
214
211
|
if Nodes::Expression === args[0]
|
215
212
|
expr = args[0]
|
216
213
|
else
|
217
|
-
return maybe_raise Errors::InvalidTypeError,
|
214
|
+
return maybe_raise Errors::InvalidTypeError, 'function map() expects the first argument to be an expression'
|
218
215
|
end
|
219
216
|
if args[1].respond_to?(:to_ary)
|
220
217
|
list = args[1].to_ary
|
221
218
|
else
|
222
|
-
return maybe_raise Errors::InvalidTypeError,
|
219
|
+
return maybe_raise Errors::InvalidTypeError, 'function map() expects the second argument to be an list'
|
223
220
|
end
|
224
221
|
list.map { |value| expr.eval(value) }
|
225
222
|
end
|
226
|
-
|
227
223
|
end
|
228
224
|
|
229
225
|
class MaxFunction < Function
|
@@ -235,7 +231,7 @@ module JMESPath
|
|
235
231
|
if args.count == 1
|
236
232
|
values = args.first
|
237
233
|
else
|
238
|
-
return maybe_raise Errors::InvalidArityError,
|
234
|
+
return maybe_raise Errors::InvalidArityError, 'function max() expects one argument'
|
239
235
|
end
|
240
236
|
if values.respond_to?(:to_ary)
|
241
237
|
values = values.to_ary
|
@@ -243,7 +239,7 @@ module JMESPath
|
|
243
239
|
first = values.first
|
244
240
|
first_type = get_type(first)
|
245
241
|
unless first_type == NUMBER_TYPE || first_type == STRING_TYPE
|
246
|
-
msg =
|
242
|
+
msg = String.new('function max() expects numeric or string values')
|
247
243
|
return maybe_raise Errors::InvalidTypeError, msg
|
248
244
|
end
|
249
245
|
values.inject([first, first_type]) do |(max, max_type), v|
|
@@ -251,13 +247,13 @@ module JMESPath
|
|
251
247
|
if max_type == v_type
|
252
248
|
v > max ? [v, v_type] : [max, max_type]
|
253
249
|
else
|
254
|
-
msg =
|
250
|
+
msg = String.new('function max() encountered a type mismatch in sequence: ')
|
255
251
|
msg << "#{max_type}, #{v_type}"
|
256
252
|
return maybe_raise Errors::InvalidTypeError, msg
|
257
253
|
end
|
258
254
|
end.first
|
259
255
|
else
|
260
|
-
return maybe_raise Errors::InvalidTypeError,
|
256
|
+
return maybe_raise Errors::InvalidTypeError, 'function max() expects an array'
|
261
257
|
end
|
262
258
|
end
|
263
259
|
end
|
@@ -271,7 +267,7 @@ module JMESPath
|
|
271
267
|
if args.count == 1
|
272
268
|
values = args.first
|
273
269
|
else
|
274
|
-
return maybe_raise Errors::InvalidArityError,
|
270
|
+
return maybe_raise Errors::InvalidArityError, 'function min() expects one argument'
|
275
271
|
end
|
276
272
|
if values.respond_to?(:to_ary)
|
277
273
|
values = values.to_ary
|
@@ -279,7 +275,7 @@ module JMESPath
|
|
279
275
|
first = values.first
|
280
276
|
first_type = get_type(first)
|
281
277
|
unless first_type == NUMBER_TYPE || first_type == STRING_TYPE
|
282
|
-
msg =
|
278
|
+
msg = String.new('function min() expects numeric or string values')
|
283
279
|
return maybe_raise Errors::InvalidTypeError, msg
|
284
280
|
end
|
285
281
|
values.inject([first, first_type]) do |(min, min_type), v|
|
@@ -287,13 +283,13 @@ module JMESPath
|
|
287
283
|
if min_type == v_type
|
288
284
|
v < min ? [v, v_type] : [min, min_type]
|
289
285
|
else
|
290
|
-
msg =
|
286
|
+
msg = String.new('function min() encountered a type mismatch in sequence: ')
|
291
287
|
msg << "#{min_type}, #{v_type}"
|
292
288
|
return maybe_raise Errors::InvalidTypeError, msg
|
293
289
|
end
|
294
290
|
end.first
|
295
291
|
else
|
296
|
-
return maybe_raise Errors::InvalidTypeError,
|
292
|
+
return maybe_raise Errors::InvalidTypeError, 'function min() expects an array'
|
297
293
|
end
|
298
294
|
end
|
299
295
|
end
|
@@ -307,7 +303,7 @@ module JMESPath
|
|
307
303
|
if args.count == 1
|
308
304
|
TYPE_NAMES[get_type(args.first)]
|
309
305
|
else
|
310
|
-
return maybe_raise Errors::InvalidArityError,
|
306
|
+
return maybe_raise Errors::InvalidArityError, 'function type() expects one argument'
|
311
307
|
end
|
312
308
|
end
|
313
309
|
end
|
@@ -323,10 +319,10 @@ module JMESPath
|
|
323
319
|
elsif value.is_a?(Struct)
|
324
320
|
value.members.map(&:to_s)
|
325
321
|
else
|
326
|
-
return maybe_raise Errors::InvalidTypeError,
|
322
|
+
return maybe_raise Errors::InvalidTypeError, 'function keys() expects a hash'
|
327
323
|
end
|
328
324
|
else
|
329
|
-
return maybe_raise Errors::InvalidArityError,
|
325
|
+
return maybe_raise Errors::InvalidArityError, 'function keys() expects one argument'
|
330
326
|
end
|
331
327
|
end
|
332
328
|
end
|
@@ -344,10 +340,10 @@ module JMESPath
|
|
344
340
|
elsif value.respond_to?(:to_ary)
|
345
341
|
value.to_ary
|
346
342
|
else
|
347
|
-
return maybe_raise Errors::InvalidTypeError,
|
343
|
+
return maybe_raise Errors::InvalidTypeError, 'function values() expects an array or a hash'
|
348
344
|
end
|
349
345
|
else
|
350
|
-
return maybe_raise Errors::InvalidArityError,
|
346
|
+
return maybe_raise Errors::InvalidArityError, 'function values() expects one argument'
|
351
347
|
end
|
352
348
|
end
|
353
349
|
end
|
@@ -360,14 +356,14 @@ module JMESPath
|
|
360
356
|
glue = args[0]
|
361
357
|
values = args[1]
|
362
358
|
if !glue.respond_to?(:to_str)
|
363
|
-
return maybe_raise Errors::InvalidTypeError,
|
359
|
+
return maybe_raise Errors::InvalidTypeError, 'function join() expects the first argument to be a string'
|
364
360
|
elsif values.respond_to?(:to_ary) && values.to_ary.all? { |v| v.respond_to?(:to_str) }
|
365
361
|
values.to_ary.join(glue)
|
366
362
|
else
|
367
|
-
return maybe_raise Errors::InvalidTypeError,
|
363
|
+
return maybe_raise Errors::InvalidTypeError, 'function join() expects values to be an array of strings'
|
368
364
|
end
|
369
365
|
else
|
370
|
-
return maybe_raise Errors::InvalidArityError,
|
366
|
+
return maybe_raise Errors::InvalidArityError, 'function join() expects an array of strings'
|
371
367
|
end
|
372
368
|
end
|
373
369
|
end
|
@@ -380,7 +376,7 @@ module JMESPath
|
|
380
376
|
value = args.first
|
381
377
|
value.respond_to?(:to_str) ? value.to_str : value.to_json
|
382
378
|
else
|
383
|
-
return maybe_raise Errors::InvalidArityError,
|
379
|
+
return maybe_raise Errors::InvalidArityError, 'function to_string() expects one argument'
|
384
380
|
end
|
385
381
|
end
|
386
382
|
end
|
@@ -397,7 +393,7 @@ module JMESPath
|
|
397
393
|
nil
|
398
394
|
end
|
399
395
|
else
|
400
|
-
return maybe_raise Errors::InvalidArityError,
|
396
|
+
return maybe_raise Errors::InvalidArityError, 'function to_number() expects one argument'
|
401
397
|
end
|
402
398
|
end
|
403
399
|
end
|
@@ -407,15 +403,15 @@ module JMESPath
|
|
407
403
|
|
408
404
|
def call(args)
|
409
405
|
if args.count == 1 && args.first.respond_to?(:to_ary)
|
410
|
-
args.first.to_ary.inject(0) do |sum,n|
|
406
|
+
args.first.to_ary.inject(0) do |sum, n|
|
411
407
|
if Numeric === n
|
412
408
|
sum + n
|
413
409
|
else
|
414
|
-
return maybe_raise Errors::InvalidTypeError,
|
410
|
+
return maybe_raise Errors::InvalidTypeError, 'function sum() expects values to be numeric'
|
415
411
|
end
|
416
412
|
end
|
417
413
|
else
|
418
|
-
return maybe_raise Errors::InvalidArityError,
|
414
|
+
return maybe_raise Errors::InvalidArityError, 'function sum() expects one argument'
|
419
415
|
end
|
420
416
|
end
|
421
417
|
end
|
@@ -427,7 +423,7 @@ module JMESPath
|
|
427
423
|
if args.count > 0
|
428
424
|
args.find { |value| !value.nil? }
|
429
425
|
else
|
430
|
-
return maybe_raise Errors::InvalidArityError,
|
426
|
+
return maybe_raise Errors::InvalidArityError, 'function not_null() expects one or more arguments'
|
431
427
|
end
|
432
428
|
end
|
433
429
|
end
|
@@ -444,26 +440,26 @@ module JMESPath
|
|
444
440
|
value = value.to_ary
|
445
441
|
# every element in the list must be of the same type
|
446
442
|
array_type = get_type(value[0])
|
447
|
-
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || value.
|
443
|
+
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || value.empty?
|
448
444
|
# stable sort
|
449
445
|
n = 0
|
450
446
|
value.sort_by do |v|
|
451
447
|
value_type = get_type(v)
|
452
448
|
if value_type != array_type
|
453
|
-
msg =
|
449
|
+
msg = 'function sort() expects values to be an array of only numbers, or only integers'
|
454
450
|
return maybe_raise Errors::InvalidTypeError, msg
|
455
451
|
end
|
456
452
|
n += 1
|
457
453
|
[v, n]
|
458
454
|
end
|
459
455
|
else
|
460
|
-
return maybe_raise Errors::InvalidTypeError,
|
456
|
+
return maybe_raise Errors::InvalidTypeError, 'function sort() expects values to be an array of numbers or integers'
|
461
457
|
end
|
462
458
|
else
|
463
|
-
return maybe_raise Errors::InvalidTypeError,
|
459
|
+
return maybe_raise Errors::InvalidTypeError, 'function sort() expects values to be an array of numbers or integers'
|
464
460
|
end
|
465
461
|
else
|
466
|
-
return maybe_raise Errors::InvalidArityError,
|
462
|
+
return maybe_raise Errors::InvalidArityError, 'function sort() expects one argument'
|
467
463
|
end
|
468
464
|
end
|
469
465
|
end
|
@@ -479,27 +475,27 @@ module JMESPath
|
|
479
475
|
values = args[0].to_ary
|
480
476
|
expression = args[1]
|
481
477
|
array_type = get_type(expression.eval(values[0]))
|
482
|
-
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || values.
|
478
|
+
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || values.empty?
|
483
479
|
# stable sort the list
|
484
480
|
n = 0
|
485
481
|
values.sort_by do |value|
|
486
482
|
value = expression.eval(value)
|
487
483
|
value_type = get_type(value)
|
488
484
|
if value_type != array_type
|
489
|
-
msg =
|
485
|
+
msg = 'function sort() expects values to be an array of only numbers, or only integers'
|
490
486
|
return maybe_raise Errors::InvalidTypeError, msg
|
491
487
|
end
|
492
488
|
n += 1
|
493
489
|
[value, n]
|
494
490
|
end
|
495
491
|
else
|
496
|
-
return maybe_raise Errors::InvalidTypeError,
|
492
|
+
return maybe_raise Errors::InvalidTypeError, 'function sort() expects values to be an array of numbers or integers'
|
497
493
|
end
|
498
494
|
else
|
499
|
-
return maybe_raise Errors::InvalidTypeError,
|
495
|
+
return maybe_raise Errors::InvalidTypeError, 'function sort_by() expects an array and an expression'
|
500
496
|
end
|
501
497
|
else
|
502
|
-
return maybe_raise Errors::InvalidArityError,
|
498
|
+
return maybe_raise Errors::InvalidArityError, 'function sort_by() expects two arguments'
|
503
499
|
end
|
504
500
|
end
|
505
501
|
end
|
@@ -522,7 +518,7 @@ module JMESPath
|
|
522
518
|
value = expression.eval(entry)
|
523
519
|
value_type = get_type(value)
|
524
520
|
if value_type != type
|
525
|
-
msg = "function #{mode}() encountered a type mismatch in "
|
521
|
+
msg = String.new("function #{mode}() encountered a type mismatch in ")
|
526
522
|
msg << "sequence: #{type}, #{value_type}"
|
527
523
|
return maybe_raise Errors::InvalidTypeError, msg
|
528
524
|
end
|
@@ -570,16 +566,16 @@ module JMESPath
|
|
570
566
|
search_type = get_type(search)
|
571
567
|
suffix_type = get_type(suffix)
|
572
568
|
if search_type != STRING_TYPE
|
573
|
-
msg =
|
569
|
+
msg = 'function ends_with() expects first argument to be a string'
|
574
570
|
return maybe_raise Errors::InvalidTypeError, msg
|
575
571
|
end
|
576
572
|
if suffix_type != STRING_TYPE
|
577
|
-
msg =
|
573
|
+
msg = 'function ends_with() expects second argument to be a string'
|
578
574
|
return maybe_raise Errors::InvalidTypeError, msg
|
579
575
|
end
|
580
576
|
search.end_with?(suffix)
|
581
577
|
else
|
582
|
-
msg =
|
578
|
+
msg = 'function ends_with() expects two arguments'
|
583
579
|
return maybe_raise Errors::InvalidArityError, msg
|
584
580
|
end
|
585
581
|
end
|
@@ -596,16 +592,16 @@ module JMESPath
|
|
596
592
|
search_type = get_type(search)
|
597
593
|
prefix_type = get_type(prefix)
|
598
594
|
if search_type != STRING_TYPE
|
599
|
-
msg =
|
595
|
+
msg = 'function starts_with() expects first argument to be a string'
|
600
596
|
return maybe_raise Errors::InvalidTypeError, msg
|
601
597
|
end
|
602
598
|
if prefix_type != STRING_TYPE
|
603
|
-
msg =
|
599
|
+
msg = 'function starts_with() expects second argument to be a string'
|
604
600
|
return maybe_raise Errors::InvalidTypeError, msg
|
605
601
|
end
|
606
602
|
search.start_with?(prefix)
|
607
603
|
else
|
608
|
-
msg =
|
604
|
+
msg = 'function starts_with() expects two arguments'
|
609
605
|
return maybe_raise Errors::InvalidArityError, msg
|
610
606
|
end
|
611
607
|
end
|
@@ -616,7 +612,7 @@ module JMESPath
|
|
616
612
|
|
617
613
|
def call(args)
|
618
614
|
if args.count == 0
|
619
|
-
msg =
|
615
|
+
msg = 'function merge() expects 1 or more arguments'
|
620
616
|
return maybe_raise Errors::InvalidArityError, msg
|
621
617
|
end
|
622
618
|
args.inject({}) do |h, v|
|
@@ -630,7 +626,7 @@ module JMESPath
|
|
630
626
|
|
631
627
|
def call(args)
|
632
628
|
if args.count == 0
|
633
|
-
msg =
|
629
|
+
msg = 'function reverse() expects 1 or more arguments'
|
634
630
|
return maybe_raise Errors::InvalidArityError, msg
|
635
631
|
end
|
636
632
|
value = args.first
|
@@ -639,7 +635,7 @@ module JMESPath
|
|
639
635
|
elsif value.respond_to?(:to_str)
|
640
636
|
value.to_str.reverse
|
641
637
|
else
|
642
|
-
msg =
|
638
|
+
msg = 'function reverse() expects an array or string'
|
643
639
|
return maybe_raise Errors::InvalidTypeError, msg
|
644
640
|
end
|
645
641
|
end
|
data/lib/jmespath/nodes/index.rb
CHANGED
data/lib/jmespath/nodes/not.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
module Nodes
|
3
4
|
class Not < Node
|
4
|
-
|
5
5
|
def initialize(expression)
|
6
6
|
@expression = expression
|
7
7
|
end
|
@@ -13,7 +13,6 @@ module JMESPath
|
|
13
13
|
def optimize
|
14
14
|
self.class.new(@expression.optimize)
|
15
15
|
end
|
16
|
-
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
data/lib/jmespath/nodes/or.rb
CHANGED
data/lib/jmespath/nodes/pipe.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -12,9 +13,7 @@ module JMESPath
|
|
12
13
|
list = []
|
13
14
|
targets.each do |v|
|
14
15
|
vv = @projection.visit(v)
|
15
|
-
unless vv.nil?
|
16
|
-
list << vv
|
17
|
-
end
|
16
|
+
list << vv unless vv.nil?
|
18
17
|
end
|
19
18
|
list
|
20
19
|
end
|
@@ -30,7 +29,7 @@ module JMESPath
|
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
|
-
def extract_targets(
|
32
|
+
def extract_targets(_left_value)
|
34
33
|
nil
|
35
34
|
end
|
36
35
|
end
|
@@ -45,11 +44,7 @@ module JMESPath
|
|
45
44
|
|
46
45
|
class ArrayProjection < Projection
|
47
46
|
def extract_targets(target)
|
48
|
-
if target.respond_to?(:to_ary)
|
49
|
-
target.to_ary
|
50
|
-
else
|
51
|
-
nil
|
52
|
-
end
|
47
|
+
target.to_ary if target.respond_to?(:to_ary)
|
53
48
|
end
|
54
49
|
|
55
50
|
def fast_instance
|
@@ -67,8 +62,6 @@ module JMESPath
|
|
67
62
|
target.to_hash.values
|
68
63
|
elsif target.is_a?(Struct)
|
69
64
|
target.values
|
70
|
-
else
|
71
|
-
nil
|
72
65
|
end
|
73
66
|
end
|
74
67
|
|
data/lib/jmespath/nodes/slice.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -6,7 +7,7 @@ module JMESPath
|
|
6
7
|
@start = start
|
7
8
|
@stop = stop
|
8
9
|
@step = step
|
9
|
-
raise Errors::InvalidValueError
|
10
|
+
raise Errors::InvalidValueError, 'slice step cannot be 0' if @step == 0
|
10
11
|
end
|
11
12
|
|
12
13
|
def visit(value)
|
@@ -27,8 +28,6 @@ module JMESPath
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
value.respond_to?(:to_str) ? result.join : result
|
30
|
-
else
|
31
|
-
nil
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
@@ -43,21 +42,19 @@ module JMESPath
|
|
43
42
|
private
|
44
43
|
|
45
44
|
def adjust_slice(length, start, stop, step)
|
46
|
-
if step.nil?
|
47
|
-
step = 1
|
48
|
-
end
|
45
|
+
step = 1 if step.nil?
|
49
46
|
|
50
|
-
if start.nil?
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
start = if start.nil?
|
48
|
+
step < 0 ? length - 1 : 0
|
49
|
+
else
|
50
|
+
adjust_endpoint(length, start, step)
|
51
|
+
end
|
55
52
|
|
56
|
-
if stop.nil?
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
stop = if stop.nil?
|
54
|
+
step < 0 ? -1 : length
|
55
|
+
else
|
56
|
+
adjust_endpoint(length, stop, step)
|
57
|
+
end
|
61
58
|
[start, stop, step]
|
62
59
|
end
|
63
60
|
|
@@ -82,8 +79,6 @@ module JMESPath
|
|
82
79
|
def visit(value)
|
83
80
|
if (value = value.respond_to?(:to_str) ? value.to_str : value.respond_to?(:to_ary) ? value.to_ary : nil)
|
84
81
|
value[@start, @stop - @start]
|
85
|
-
else
|
86
|
-
nil
|
87
82
|
end
|
88
83
|
end
|
89
84
|
end
|
data/lib/jmespath/nodes.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -9,11 +10,11 @@ module JMESPath
|
|
9
10
|
self
|
10
11
|
end
|
11
12
|
|
12
|
-
def chains_with?(
|
13
|
+
def chains_with?(_other)
|
13
14
|
false
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
require 'jmespath/nodes/subexpression'
|
18
19
|
require 'jmespath/nodes/and'
|
19
20
|
require 'jmespath/nodes/comparator'
|
@@ -35,7 +36,5 @@ module JMESPath
|
|
35
36
|
require 'jmespath/nodes/projection'
|
36
37
|
require 'jmespath/nodes/projection'
|
37
38
|
require 'jmespath/nodes/slice'
|
38
|
-
|
39
|
-
|
40
39
|
end
|
41
40
|
end
|