jmespath 1.3.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of jmespath might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/VERSION +1 -0
- data/lib/jmespath/lexer.rb +34 -1
- data/lib/jmespath/nodes/comparator.rb +30 -6
- data/lib/jmespath/nodes/condition.rb +17 -8
- data/lib/jmespath/nodes/field.rb +8 -6
- data/lib/jmespath/nodes/flatten.rb +4 -4
- data/lib/jmespath/nodes/function.rb +61 -40
- data/lib/jmespath/nodes/projection.rb +5 -3
- data/lib/jmespath/nodes/slice.rb +3 -3
- data/lib/jmespath/nodes.rb +0 -4
- data/lib/jmespath/parser.rb +1 -1
- data/lib/jmespath/util.rb +17 -1
- data/lib/jmespath/version.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09a128a1330ef64e0a59ae48084fa404aa705184bdf2cf2a74d477dda596aa25'
|
4
|
+
data.tar.gz: 50ecb149f81b2a468a24de16ce5b91b0ec5300e1d1b3a16022138b0fb4a50374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66052e2a8b1cb4d9bbbb5b8e7e40b5f6cf8df91cf260e27d7ed4d32e129003c4a20bd92cd39afa168d4959400b450bb36876f6e23c4b0a440cb8e8a99d9e0d6
|
7
|
+
data.tar.gz: 25fc0eec3d98c4722e1792771cab62b59b5ebe1e740c6556e5d76ad23d6f248b636816eaa2c3613e523b15e5cd95917e8dad1627dfcb3abd61c4e25b716b068e
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.6.0
|
data/lib/jmespath/lexer.rb
CHANGED
@@ -295,7 +295,40 @@ module JMESPath
|
|
295
295
|
Token.new(type, buffer.join, position)
|
296
296
|
end
|
297
297
|
|
298
|
-
|
298
|
+
# Certain versions of Ruby and of the pure_json gem not support loading
|
299
|
+
# scalar JSON values, such a numbers, booleans, strings, etc. These
|
300
|
+
# simple values must be first wrapped inside a JSON object before calling
|
301
|
+
# `JSON.load`.
|
302
|
+
#
|
303
|
+
# # works in most JSON versions, raises in some versions
|
304
|
+
# JSON.load("true")
|
305
|
+
# JSON.load("123")
|
306
|
+
# JSON.load("\"abc\"")
|
307
|
+
#
|
308
|
+
# This is an known issue for:
|
309
|
+
#
|
310
|
+
# * Ruby 1.9.3 bundled v1.5.5 of json; Ruby 1.9.3 defaults to bundled
|
311
|
+
# version despite newer versions being available.
|
312
|
+
#
|
313
|
+
# * json_pure v2.0.0+
|
314
|
+
#
|
315
|
+
# It is not possible to change the version of JSON loaded in the
|
316
|
+
# user's application. Adding an explicit dependency on json gem
|
317
|
+
# causes issues in environments that cannot compile the gem. We previously
|
318
|
+
# had a direct dependency on `json_pure`, but this broke with the v2 update.
|
319
|
+
#
|
320
|
+
# This method allows us to detect how the `JSON.load` behaves so we know
|
321
|
+
# if we have to wrap scalar JSON values to parse them or not.
|
322
|
+
# @api private
|
323
|
+
def self.requires_wrapping?
|
324
|
+
begin
|
325
|
+
JSON.load('false')
|
326
|
+
rescue JSON::ParserError
|
327
|
+
true
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
if requires_wrapping?
|
299
332
|
def parse_json(token, quoted = false)
|
300
333
|
begin
|
301
334
|
if quoted
|
@@ -2,6 +2,8 @@ module JMESPath
|
|
2
2
|
# @api private
|
3
3
|
module Nodes
|
4
4
|
class Comparator < Node
|
5
|
+
COMPARABLE_TYPES = [Numeric, String].freeze
|
6
|
+
|
5
7
|
attr_reader :left, :right
|
6
8
|
|
7
9
|
def initialize(left, right)
|
@@ -36,43 +38,65 @@ module JMESPath
|
|
36
38
|
def check(left_value, right_value)
|
37
39
|
nil
|
38
40
|
end
|
41
|
+
|
42
|
+
def comparable?(left_value, right_value)
|
43
|
+
COMPARABLE_TYPES.any? do |type|
|
44
|
+
left_value.is_a?(type) && right_value.is_a?(type)
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
module Comparators
|
42
50
|
|
43
51
|
class Eq < Comparator
|
44
52
|
def check(left_value, right_value)
|
45
|
-
left_value == right_value
|
53
|
+
Util.as_json(left_value) == Util.as_json(right_value)
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
49
57
|
class Neq < Comparator
|
50
58
|
def check(left_value, right_value)
|
51
|
-
left_value != right_value
|
59
|
+
Util.as_json(left_value) != Util.as_json(right_value)
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
55
63
|
class Gt < Comparator
|
56
64
|
def check(left_value, right_value)
|
57
|
-
|
65
|
+
if comparable?(left_value, right_value)
|
66
|
+
left_value > right_value
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
58
70
|
end
|
59
71
|
end
|
60
72
|
|
61
73
|
class Gte < Comparator
|
62
74
|
def check(left_value, right_value)
|
63
|
-
|
75
|
+
if comparable?(left_value, right_value)
|
76
|
+
left_value >= right_value
|
77
|
+
else
|
78
|
+
nil
|
79
|
+
end
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
67
83
|
class Lt < Comparator
|
68
84
|
def check(left_value, right_value)
|
69
|
-
|
85
|
+
if comparable?(left_value, right_value)
|
86
|
+
left_value < right_value
|
87
|
+
else
|
88
|
+
nil
|
89
|
+
end
|
70
90
|
end
|
71
91
|
end
|
72
92
|
|
73
93
|
class Lte < Comparator
|
74
94
|
def check(left_value, right_value)
|
75
|
-
|
95
|
+
if comparable?(left_value, right_value)
|
96
|
+
left_value <= right_value
|
97
|
+
else
|
98
|
+
nil
|
99
|
+
end
|
76
100
|
end
|
77
101
|
end
|
78
102
|
end
|
@@ -27,6 +27,7 @@ module JMESPath
|
|
27
27
|
|
28
28
|
class ComparatorCondition < Node
|
29
29
|
COMPARATOR_TO_CONDITION = {}
|
30
|
+
COMPARABLE_TYPES = [Integer, String].freeze
|
30
31
|
|
31
32
|
def initialize(left, right, child)
|
32
33
|
@left = left
|
@@ -37,13 +38,21 @@ module JMESPath
|
|
37
38
|
def visit(value)
|
38
39
|
nil
|
39
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def comparable?(left_value, right_value)
|
45
|
+
COMPARABLE_TYPES.any? do |type|
|
46
|
+
left_value.is_a?(type) && right_value.is_a?(type)
|
47
|
+
end
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
51
|
class EqCondition < ComparatorCondition
|
43
52
|
COMPARATOR_TO_CONDITION[Comparators::Eq] = self
|
44
53
|
|
45
54
|
def visit(value)
|
46
|
-
@left.visit(value) == @right.visit(value) ? @child.visit(value) : nil
|
55
|
+
Util.as_json(@left.visit(value)) == Util.as_json(@right.visit(value)) ? @child.visit(value) : nil
|
47
56
|
end
|
48
57
|
|
49
58
|
def optimize
|
@@ -62,7 +71,7 @@ module JMESPath
|
|
62
71
|
end
|
63
72
|
|
64
73
|
def visit(value)
|
65
|
-
@left.visit(value) == @right ? @child.visit(value) : nil
|
74
|
+
Util.as_json(@left.visit(value)) == @right ? @child.visit(value) : nil
|
66
75
|
end
|
67
76
|
end
|
68
77
|
|
@@ -70,7 +79,7 @@ module JMESPath
|
|
70
79
|
COMPARATOR_TO_CONDITION[Comparators::Neq] = self
|
71
80
|
|
72
81
|
def visit(value)
|
73
|
-
@left.visit(value) != @right.visit(value) ? @child.visit(value) : nil
|
82
|
+
Util.as_json(@left.visit(value)) != Util.as_json(@right.visit(value)) ? @child.visit(value) : nil
|
74
83
|
end
|
75
84
|
|
76
85
|
def optimize
|
@@ -89,7 +98,7 @@ module JMESPath
|
|
89
98
|
end
|
90
99
|
|
91
100
|
def visit(value)
|
92
|
-
@left.visit(value) != @right ? @child.visit(value) : nil
|
101
|
+
Util.as_json(@left.visit(value)) != @right ? @child.visit(value) : nil
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
@@ -99,7 +108,7 @@ module JMESPath
|
|
99
108
|
def visit(value)
|
100
109
|
left_value = @left.visit(value)
|
101
110
|
right_value = @right.visit(value)
|
102
|
-
|
111
|
+
comparable?(left_value, right_value) && left_value > right_value ? @child.visit(value) : nil
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
@@ -109,7 +118,7 @@ module JMESPath
|
|
109
118
|
def visit(value)
|
110
119
|
left_value = @left.visit(value)
|
111
120
|
right_value = @right.visit(value)
|
112
|
-
|
121
|
+
comparable?(left_value, right_value) && left_value >= right_value ? @child.visit(value) : nil
|
113
122
|
end
|
114
123
|
end
|
115
124
|
|
@@ -119,7 +128,7 @@ module JMESPath
|
|
119
128
|
def visit(value)
|
120
129
|
left_value = @left.visit(value)
|
121
130
|
right_value = @right.visit(value)
|
122
|
-
|
131
|
+
comparable?(left_value, right_value) && left_value < right_value ? @child.visit(value) : nil
|
123
132
|
end
|
124
133
|
end
|
125
134
|
|
@@ -129,7 +138,7 @@ module JMESPath
|
|
129
138
|
def visit(value)
|
130
139
|
left_value = @left.visit(value)
|
131
140
|
right_value = @right.visit(value)
|
132
|
-
|
141
|
+
comparable?(left_value, right_value) && left_value <= right_value ? @child.visit(value) : nil
|
133
142
|
end
|
134
143
|
end
|
135
144
|
end
|
data/lib/jmespath/nodes/field.rb
CHANGED
@@ -8,9 +8,10 @@ module JMESPath
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def visit(value)
|
11
|
-
if value.
|
12
|
-
value[@key]
|
13
|
-
elsif value.
|
11
|
+
if value.respond_to?(:to_ary) && @key.is_a?(Integer)
|
12
|
+
value.to_ary[@key]
|
13
|
+
elsif value.respond_to?(:to_hash)
|
14
|
+
value = value.to_hash
|
14
15
|
if !(v = value[@key]).nil?
|
15
16
|
v
|
16
17
|
elsif @key_sym && !(v = value[@key_sym]).nil?
|
@@ -48,9 +49,10 @@ module JMESPath
|
|
48
49
|
|
49
50
|
def visit(obj)
|
50
51
|
@keys.reduce(obj) do |value, key|
|
51
|
-
if value.
|
52
|
-
value[key]
|
53
|
-
elsif value.
|
52
|
+
if value.respond_to?(:to_ary) && key.is_a?(Integer)
|
53
|
+
value.to_ary[key]
|
54
|
+
elsif value.respond_to?(:to_hash)
|
55
|
+
value = value.to_hash
|
54
56
|
if !(v = value[key]).nil?
|
55
57
|
v
|
56
58
|
elsif (sym = @key_syms[key]) && !(v = value[sym]).nil?
|
@@ -8,10 +8,10 @@ module JMESPath
|
|
8
8
|
|
9
9
|
def visit(value)
|
10
10
|
value = @child.visit(value)
|
11
|
-
if
|
12
|
-
value.each_with_object([]) do |v, values|
|
13
|
-
if
|
14
|
-
values.concat(v)
|
11
|
+
if value.respond_to?(:to_ary)
|
12
|
+
value.to_ary.each_with_object([]) do |v, values|
|
13
|
+
if v.respond_to?(:to_ary)
|
14
|
+
values.concat(v.to_ary)
|
15
15
|
else
|
16
16
|
values.push(v)
|
17
17
|
end
|
@@ -50,14 +50,20 @@ module JMESPath
|
|
50
50
|
|
51
51
|
module TypeChecker
|
52
52
|
def get_type(value)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
if value.respond_to?(:to_str)
|
54
|
+
STRING_TYPE
|
55
|
+
elsif value == true || value == false
|
56
|
+
BOOLEAN_TYPE
|
57
|
+
elsif value == nil
|
58
|
+
NULL_TYPE
|
59
|
+
elsif value.is_a?(Numeric)
|
60
|
+
NUMBER_TYPE
|
61
|
+
elsif value.respond_to?(:to_hash) || value.is_a?(Struct)
|
62
|
+
OBJECT_TYPE
|
63
|
+
elsif value.respond_to?(:to_ary)
|
64
|
+
ARRAY_TYPE
|
65
|
+
elsif value.is_a?(Expression)
|
66
|
+
EXPRESSION_TYPE
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
@@ -106,7 +112,9 @@ module JMESPath
|
|
106
112
|
else
|
107
113
|
return maybe_raise Errors::InvalidArityError, "function avg() expects one argument"
|
108
114
|
end
|
109
|
-
if
|
115
|
+
if values.respond_to?(:to_ary)
|
116
|
+
values = values.to_ary
|
117
|
+
return nil if values.empty?
|
110
118
|
values.inject(0) do |total,n|
|
111
119
|
if Numeric === n
|
112
120
|
total + n
|
@@ -143,9 +151,11 @@ module JMESPath
|
|
143
151
|
def call(args)
|
144
152
|
if args.count == 2
|
145
153
|
haystack = args[0]
|
146
|
-
needle = args[1]
|
147
|
-
if
|
148
|
-
haystack.include?(needle)
|
154
|
+
needle = Util.as_json(args[1])
|
155
|
+
if haystack.respond_to?(:to_str)
|
156
|
+
haystack.to_str.include?(needle)
|
157
|
+
elsif haystack.respond_to?(:to_ary)
|
158
|
+
haystack.to_ary.any? { |e| Util.as_json(e) == needle }
|
149
159
|
else
|
150
160
|
return maybe_raise Errors::InvalidTypeError, "contains expects 2nd arg to be a list"
|
151
161
|
end
|
@@ -181,9 +191,14 @@ module JMESPath
|
|
181
191
|
else
|
182
192
|
return maybe_raise Errors::InvalidArityError, "function length() expects one argument"
|
183
193
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
194
|
+
if value.respond_to?(:to_hash)
|
195
|
+
value.to_hash.size
|
196
|
+
elsif value.respond_to?(:to_ary)
|
197
|
+
value.to_ary.size
|
198
|
+
elsif value.respond_to?(:to_str)
|
199
|
+
value.to_str.size
|
200
|
+
else
|
201
|
+
return maybe_raise Errors::InvalidTypeError, "function length() expects string, array or object"
|
187
202
|
end
|
188
203
|
end
|
189
204
|
end
|
@@ -201,13 +216,13 @@ module JMESPath
|
|
201
216
|
else
|
202
217
|
return maybe_raise Errors::InvalidTypeError, "function map() expects the first argument to be an expression"
|
203
218
|
end
|
204
|
-
if
|
205
|
-
list = args[1]
|
219
|
+
if args[1].respond_to?(:to_ary)
|
220
|
+
list = args[1].to_ary
|
206
221
|
else
|
207
222
|
return maybe_raise Errors::InvalidTypeError, "function map() expects the second argument to be an list"
|
208
223
|
end
|
209
224
|
list.map { |value| expr.eval(value) }
|
210
|
-
|
225
|
+
end
|
211
226
|
|
212
227
|
end
|
213
228
|
|
@@ -222,7 +237,8 @@ module JMESPath
|
|
222
237
|
else
|
223
238
|
return maybe_raise Errors::InvalidArityError, "function max() expects one argument"
|
224
239
|
end
|
225
|
-
if
|
240
|
+
if values.respond_to?(:to_ary)
|
241
|
+
values = values.to_ary
|
226
242
|
return nil if values.empty?
|
227
243
|
first = values.first
|
228
244
|
first_type = get_type(first)
|
@@ -257,7 +273,8 @@ module JMESPath
|
|
257
273
|
else
|
258
274
|
return maybe_raise Errors::InvalidArityError, "function min() expects one argument"
|
259
275
|
end
|
260
|
-
if
|
276
|
+
if values.respond_to?(:to_ary)
|
277
|
+
values = values.to_ary
|
261
278
|
return nil if values.empty?
|
262
279
|
first = values.first
|
263
280
|
first_type = get_type(first)
|
@@ -301,12 +318,10 @@ module JMESPath
|
|
301
318
|
def call(args)
|
302
319
|
if args.count == 1
|
303
320
|
value = args.first
|
304
|
-
if
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
else raise NotImplementedError
|
309
|
-
end
|
321
|
+
if value.respond_to?(:to_hash)
|
322
|
+
value.to_hash.keys.map(&:to_s)
|
323
|
+
elsif value.is_a?(Struct)
|
324
|
+
value.members.map(&:to_s)
|
310
325
|
else
|
311
326
|
return maybe_raise Errors::InvalidTypeError, "function keys() expects a hash"
|
312
327
|
end
|
@@ -322,10 +337,12 @@ module JMESPath
|
|
322
337
|
def call(args)
|
323
338
|
if args.count == 1
|
324
339
|
value = args.first
|
325
|
-
if
|
340
|
+
if value.respond_to?(:to_hash)
|
341
|
+
value.to_hash.values
|
342
|
+
elsif value.is_a?(Struct)
|
326
343
|
value.values
|
327
|
-
elsif
|
328
|
-
value
|
344
|
+
elsif value.respond_to?(:to_ary)
|
345
|
+
value.to_ary
|
329
346
|
else
|
330
347
|
return maybe_raise Errors::InvalidTypeError, "function values() expects an array or a hash"
|
331
348
|
end
|
@@ -342,10 +359,10 @@ module JMESPath
|
|
342
359
|
if args.count == 2
|
343
360
|
glue = args[0]
|
344
361
|
values = args[1]
|
345
|
-
if !(
|
362
|
+
if !glue.respond_to?(:to_str)
|
346
363
|
return maybe_raise Errors::InvalidTypeError, "function join() expects the first argument to be a string"
|
347
|
-
elsif
|
348
|
-
values.join(glue)
|
364
|
+
elsif values.respond_to?(:to_ary) && values.to_ary.all? { |v| v.respond_to?(:to_str) }
|
365
|
+
values.to_ary.join(glue)
|
349
366
|
else
|
350
367
|
return maybe_raise Errors::InvalidTypeError, "function join() expects values to be an array of strings"
|
351
368
|
end
|
@@ -361,7 +378,7 @@ module JMESPath
|
|
361
378
|
def call(args)
|
362
379
|
if args.count == 1
|
363
380
|
value = args.first
|
364
|
-
|
381
|
+
value.respond_to?(:to_str) ? value.to_str : value.to_json
|
365
382
|
else
|
366
383
|
return maybe_raise Errors::InvalidArityError, "function to_string() expects one argument"
|
367
384
|
end
|
@@ -389,8 +406,8 @@ module JMESPath
|
|
389
406
|
FUNCTIONS['sum'] = self
|
390
407
|
|
391
408
|
def call(args)
|
392
|
-
if args.count == 1 &&
|
393
|
-
args.first.inject(0) do |sum,n|
|
409
|
+
if args.count == 1 && args.first.respond_to?(:to_ary)
|
410
|
+
args.first.to_ary.inject(0) do |sum,n|
|
394
411
|
if Numeric === n
|
395
412
|
sum + n
|
396
413
|
else
|
@@ -423,7 +440,8 @@ module JMESPath
|
|
423
440
|
def call(args)
|
424
441
|
if args.count == 1
|
425
442
|
value = args.first
|
426
|
-
if
|
443
|
+
if value.respond_to?(:to_ary)
|
444
|
+
value = value.to_ary
|
427
445
|
# every element in the list must be of the same type
|
428
446
|
array_type = get_type(value[0])
|
429
447
|
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || value.size == 0
|
@@ -458,7 +476,7 @@ module JMESPath
|
|
458
476
|
def call(args)
|
459
477
|
if args.count == 2
|
460
478
|
if get_type(args[0]) == ARRAY_TYPE && get_type(args[1]) == EXPRESSION_TYPE
|
461
|
-
values = args[0]
|
479
|
+
values = args[0].to_ary
|
462
480
|
expression = args[1]
|
463
481
|
array_type = get_type(expression.eval(values[0]))
|
464
482
|
if array_type == STRING_TYPE || array_type == NUMBER_TYPE || values.size == 0
|
@@ -494,6 +512,7 @@ module JMESPath
|
|
494
512
|
values = args[0]
|
495
513
|
expression = args[1]
|
496
514
|
if get_type(values) == ARRAY_TYPE && get_type(expression) == EXPRESSION_TYPE
|
515
|
+
values = values.to_ary
|
497
516
|
type = get_type(expression.eval(values.first))
|
498
517
|
if type != NUMBER_TYPE && type != STRING_TYPE
|
499
518
|
msg = "function #{mode}() expects values to be strings or numbers"
|
@@ -615,8 +634,10 @@ module JMESPath
|
|
615
634
|
return maybe_raise Errors::InvalidArityError, msg
|
616
635
|
end
|
617
636
|
value = args.first
|
618
|
-
if
|
619
|
-
value.reverse
|
637
|
+
if value.respond_to?(:to_ary)
|
638
|
+
value.to_ary.reverse
|
639
|
+
elsif value.respond_to?(:to_str)
|
640
|
+
value.to_str.reverse
|
620
641
|
else
|
621
642
|
msg = "function reverse() expects an array or string"
|
622
643
|
return maybe_raise Errors::InvalidTypeError, msg
|
@@ -629,7 +650,7 @@ module JMESPath
|
|
629
650
|
|
630
651
|
def call(args)
|
631
652
|
value = args.first
|
632
|
-
|
653
|
+
value.respond_to?(:to_ary) ? value.to_ary : [value]
|
633
654
|
end
|
634
655
|
end
|
635
656
|
end
|
@@ -45,8 +45,8 @@ module JMESPath
|
|
45
45
|
|
46
46
|
class ArrayProjection < Projection
|
47
47
|
def extract_targets(target)
|
48
|
-
if
|
49
|
-
target
|
48
|
+
if target.respond_to?(:to_ary)
|
49
|
+
target.to_ary
|
50
50
|
else
|
51
51
|
nil
|
52
52
|
end
|
@@ -63,7 +63,9 @@ module JMESPath
|
|
63
63
|
|
64
64
|
class ObjectProjection < Projection
|
65
65
|
def extract_targets(target)
|
66
|
-
if
|
66
|
+
if target.respond_to?(:to_hash)
|
67
|
+
target.to_hash.values
|
68
|
+
elsif target.is_a?(Struct)
|
67
69
|
target.values
|
68
70
|
else
|
69
71
|
nil
|
data/lib/jmespath/nodes/slice.rb
CHANGED
@@ -10,7 +10,7 @@ module JMESPath
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def visit(value)
|
13
|
-
if
|
13
|
+
if (value = value.respond_to?(:to_str) ? value.to_str : value.respond_to?(:to_ary) ? value.to_ary : nil)
|
14
14
|
start, stop, step = adjust_slice(value.size, @start, @stop, @step)
|
15
15
|
result = []
|
16
16
|
if step > 0
|
@@ -26,7 +26,7 @@ module JMESPath
|
|
26
26
|
i += step
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
value.respond_to?(:to_str) ? result.join : result
|
30
30
|
else
|
31
31
|
nil
|
32
32
|
end
|
@@ -80,7 +80,7 @@ module JMESPath
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def visit(value)
|
83
|
-
if
|
83
|
+
if (value = value.respond_to?(:to_str) ? value.to_str : value.respond_to?(:to_ary) ? value.to_ary : nil)
|
84
84
|
value[@start, @stop - @start]
|
85
85
|
else
|
86
86
|
nil
|
data/lib/jmespath/nodes.rb
CHANGED
data/lib/jmespath/parser.rb
CHANGED
@@ -59,7 +59,7 @@ module JMESPath
|
|
59
59
|
# @param [Integer] rbp Right binding power
|
60
60
|
def expr(stream, rbp = 0)
|
61
61
|
left = send("nud_#{stream.token.type}", stream)
|
62
|
-
while rbp < stream.token.binding_power
|
62
|
+
while rbp < (stream.token.binding_power || 0)
|
63
63
|
left = send("led_#{stream.token.type}", stream, left)
|
64
64
|
end
|
65
65
|
left
|
data/lib/jmespath/util.rb
CHANGED
@@ -9,10 +9,26 @@ module JMESPath
|
|
9
9
|
#
|
10
10
|
def falsey?(value)
|
11
11
|
!value ||
|
12
|
-
(value.respond_to?(:
|
12
|
+
(value.respond_to?(:to_ary) && value.to_ary.empty?) ||
|
13
|
+
(value.respond_to?(:to_hash) && value.to_hash.empty?) ||
|
14
|
+
(value.respond_to?(:to_str) && value.to_str.empty?) ||
|
13
15
|
(value.respond_to?(:entries) && !value.entries.any?)
|
14
16
|
# final case necessary to support Enumerable and Struct
|
15
17
|
end
|
18
|
+
|
19
|
+
def as_json(value)
|
20
|
+
if value.respond_to?(:to_ary)
|
21
|
+
value.to_ary.map { |e| as_json(e) }
|
22
|
+
elsif value.respond_to?(:to_hash)
|
23
|
+
hash = {}
|
24
|
+
value.to_hash.each_pair { |k, v| hash[k] = as_json(v) }
|
25
|
+
hash
|
26
|
+
elsif value.respond_to?(:to_str)
|
27
|
+
value.to_str
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
18
34
|
end
|
data/lib/jmespath/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jmespath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Rowe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Implements JMESPath for Ruby
|
14
14
|
email: trevorrowe@gmail.com
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- LICENSE.txt
|
20
|
+
- VERSION
|
20
21
|
- lib/jmespath.rb
|
21
22
|
- lib/jmespath/caching_parser.rb
|
22
23
|
- lib/jmespath/errors.rb
|
@@ -48,9 +49,9 @@ files:
|
|
48
49
|
- lib/jmespath/version.rb
|
49
50
|
homepage: http://github.com/trevorrowe/jmespath.rb
|
50
51
|
licenses:
|
51
|
-
- Apache
|
52
|
+
- Apache-2.0
|
52
53
|
metadata: {}
|
53
|
-
post_install_message:
|
54
|
+
post_install_message:
|
54
55
|
rdoc_options: []
|
55
56
|
require_paths:
|
56
57
|
- lib
|
@@ -65,10 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: '0'
|
67
68
|
requirements: []
|
68
|
-
|
69
|
-
|
70
|
-
signing_key:
|
69
|
+
rubygems_version: 3.2.3
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: JMESPath - Ruby Edition
|
73
73
|
test_files: []
|
74
|
-
has_rdoc:
|