jmespath 1.4.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f2d08f64e74ad4927d6323f98b91486ad7d8f79c
4
- data.tar.gz: ce7796a88dab9241efacdeac1a3b36c9083ff6ca
2
+ SHA256:
3
+ metadata.gz: e9276a9f614d19179d10e5e166950070fdbce091b7154ea2c15e700ca155ab4e
4
+ data.tar.gz: e3a122d91c10056382b50876583f550be0bf07a015c68ffaaff8cb2c3e4fcacf
5
5
  SHA512:
6
- metadata.gz: ca3d9a98c00cedf8b5bafdc70d3cdb8b2ee754ef85dfa270807650fa9517d50db68e513d3713d431ac8ac1b9bdb9757ca76b2758bc8ddfde1add3eedb08973e4
7
- data.tar.gz: 7c09a5ee313e2f7feba1334c240fdc2a820eb9127d5e2db3392ac1dad3b29b2b8b4c55aee4f6c4309417d857df84f8854201a79ba5fe405d724f91a44db331d3
6
+ metadata.gz: 46128b4ab5e58de1f2cdcb80a2b2e8e69690cce7455da154da4b4c18406e80a83de24c07339eca4cddef142afea29b74f131b48fe7292ce36131b8e2cd1cb80c
7
+ data.tar.gz: 0f44933d7fc3736bf71273736089b7c6787ce4127f96742b263822a7eb7123e9326f7a9512b408d9128bdd0fb6dcf8839ddceaf773c75f031c1c65436929ee42
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.6.1
@@ -298,12 +298,12 @@ module JMESPath
298
298
  # Certain versions of Ruby and of the pure_json gem not support loading
299
299
  # scalar JSON values, such a numbers, booleans, strings, etc. These
300
300
  # simple values must be first wrapped inside a JSON object before calling
301
- # `JSON.load`.
301
+ # `JSON.parse`.
302
302
  #
303
303
  # # works in most JSON versions, raises in some versions
304
- # JSON.load("true")
305
- # JSON.load("123")
306
- # JSON.load("\"abc\"")
304
+ # JSON.parse("true")
305
+ # JSON.parse("123")
306
+ # JSON.parse("\"abc\"")
307
307
  #
308
308
  # This is an known issue for:
309
309
  #
@@ -317,12 +317,12 @@ module JMESPath
317
317
  # causes issues in environments that cannot compile the gem. We previously
318
318
  # had a direct dependency on `json_pure`, but this broke with the v2 update.
319
319
  #
320
- # This method allows us to detect how the `JSON.load` behaves so we know
320
+ # This method allows us to detect how the `JSON.parse` behaves so we know
321
321
  # if we have to wrap scalar JSON values to parse them or not.
322
322
  # @api private
323
323
  def self.requires_wrapping?
324
324
  begin
325
- JSON.load('false')
325
+ JSON.parse('false')
326
326
  rescue JSON::ParserError
327
327
  true
328
328
  end
@@ -332,12 +332,12 @@ module JMESPath
332
332
  def parse_json(token, quoted = false)
333
333
  begin
334
334
  if quoted
335
- token.value = JSON.load("{\"value\":#{token.value}}")['value']
335
+ token.value = JSON.parse("{\"value\":#{token.value}}")['value']
336
336
  else
337
337
  begin
338
- token.value = JSON.load("{\"value\":#{token.value}}")['value']
338
+ token.value = JSON.parse("{\"value\":#{token.value}}")['value']
339
339
  rescue
340
- token.value = JSON.load(sprintf('{"value":"%s"}', token.value.lstrip))['value']
340
+ token.value = JSON.parse(sprintf('{"value":"%s"}', token.value.lstrip))['value']
341
341
  end
342
342
  end
343
343
  rescue JSON::ParserError
@@ -349,9 +349,9 @@ module JMESPath
349
349
  def parse_json(token, quoted = false)
350
350
  begin
351
351
  if quoted
352
- token.value = JSON.load(token.value)
352
+ token.value = JSON.parse(token.value)
353
353
  else
354
- token.value = JSON.load(token.value) rescue JSON.load(sprintf('"%s"', token.value.lstrip))
354
+ token.value = JSON.parse(token.value) rescue JSON.parse(sprintf('"%s"', token.value.lstrip))
355
355
  end
356
356
  rescue JSON::ParserError
357
357
  token.type = T_UNKNOWN
@@ -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,25 +38,31 @@ 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
- if left_value.is_a?(Numeric) && right_value.is_a?(Numeric)
65
+ if comparable?(left_value, right_value)
58
66
  left_value > right_value
59
67
  else
60
68
  nil
@@ -64,7 +72,7 @@ module JMESPath
64
72
 
65
73
  class Gte < Comparator
66
74
  def check(left_value, right_value)
67
- if left_value.is_a?(Numeric) && right_value.is_a?(Numeric)
75
+ if comparable?(left_value, right_value)
68
76
  left_value >= right_value
69
77
  else
70
78
  nil
@@ -74,7 +82,7 @@ module JMESPath
74
82
 
75
83
  class Lt < Comparator
76
84
  def check(left_value, right_value)
77
- if left_value.is_a?(Numeric) && right_value.is_a?(Numeric)
85
+ if comparable?(left_value, right_value)
78
86
  left_value < right_value
79
87
  else
80
88
  nil
@@ -84,7 +92,7 @@ module JMESPath
84
92
 
85
93
  class Lte < Comparator
86
94
  def check(left_value, right_value)
87
- if left_value.is_a?(Numeric) && right_value.is_a?(Numeric)
95
+ if comparable?(left_value, right_value)
88
96
  left_value <= right_value
89
97
  else
90
98
  nil
@@ -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
- left_value.is_a?(Integer) && right_value.is_a?(Integer) && left_value > right_value ? @child.visit(value) : nil
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
- left_value.is_a?(Integer) && right_value.is_a?(Integer) && left_value >= right_value ? @child.visit(value) : nil
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
- left_value.is_a?(Integer) && right_value.is_a?(Integer) && left_value < right_value ? @child.visit(value) : nil
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
- left_value.is_a?(Integer) && right_value.is_a?(Integer) && left_value <= right_value ? @child.visit(value) : nil
141
+ comparable?(left_value, right_value) && left_value <= right_value ? @child.visit(value) : nil
133
142
  end
134
143
  end
135
144
  end
@@ -8,9 +8,10 @@ module JMESPath
8
8
  end
9
9
 
10
10
  def visit(value)
11
- if value.is_a?(Array) && @key.is_a?(Integer)
12
- value[@key]
13
- elsif value.is_a?(Hash)
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.is_a?(Array) && key.is_a?(Integer)
52
- value[key]
53
- elsif value.is_a?(Hash)
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 Array === value
12
- value.each_with_object([]) do |v, values|
13
- if Array === v
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
- case value
54
- when String then STRING_TYPE
55
- when true, false then BOOLEAN_TYPE
56
- when nil then NULL_TYPE
57
- when Numeric then NUMBER_TYPE
58
- when Hash, Struct then OBJECT_TYPE
59
- when Array then ARRAY_TYPE
60
- when Expression then EXPRESSION_TYPE
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,8 @@ module JMESPath
106
112
  else
107
113
  return maybe_raise Errors::InvalidArityError, "function avg() expects one argument"
108
114
  end
109
- if Array === values
115
+ if values.respond_to?(:to_ary)
116
+ values = values.to_ary
110
117
  return nil if values.empty?
111
118
  values.inject(0) do |total,n|
112
119
  if Numeric === n
@@ -144,9 +151,11 @@ module JMESPath
144
151
  def call(args)
145
152
  if args.count == 2
146
153
  haystack = args[0]
147
- needle = args[1]
148
- if String === haystack || Array === haystack
149
- 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 }
150
159
  else
151
160
  return maybe_raise Errors::InvalidTypeError, "contains expects 2nd arg to be a list"
152
161
  end
@@ -182,9 +191,14 @@ module JMESPath
182
191
  else
183
192
  return maybe_raise Errors::InvalidArityError, "function length() expects one argument"
184
193
  end
185
- case value
186
- when Hash, Array, String then value.size
187
- else return maybe_raise Errors::InvalidTypeError, "function length() expects string, array or object"
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"
188
202
  end
189
203
  end
190
204
  end
@@ -202,8 +216,8 @@ module JMESPath
202
216
  else
203
217
  return maybe_raise Errors::InvalidTypeError, "function map() expects the first argument to be an expression"
204
218
  end
205
- if Array === args[1]
206
- list = args[1]
219
+ if args[1].respond_to?(:to_ary)
220
+ list = args[1].to_ary
207
221
  else
208
222
  return maybe_raise Errors::InvalidTypeError, "function map() expects the second argument to be an list"
209
223
  end
@@ -223,7 +237,8 @@ module JMESPath
223
237
  else
224
238
  return maybe_raise Errors::InvalidArityError, "function max() expects one argument"
225
239
  end
226
- if Array === values
240
+ if values.respond_to?(:to_ary)
241
+ values = values.to_ary
227
242
  return nil if values.empty?
228
243
  first = values.first
229
244
  first_type = get_type(first)
@@ -258,7 +273,8 @@ module JMESPath
258
273
  else
259
274
  return maybe_raise Errors::InvalidArityError, "function min() expects one argument"
260
275
  end
261
- if Array === values
276
+ if values.respond_to?(:to_ary)
277
+ values = values.to_ary
262
278
  return nil if values.empty?
263
279
  first = values.first
264
280
  first_type = get_type(first)
@@ -302,12 +318,10 @@ module JMESPath
302
318
  def call(args)
303
319
  if args.count == 1
304
320
  value = args.first
305
- if hash_like?(value)
306
- case value
307
- when Hash then value.keys.map(&:to_s)
308
- when Struct then value.members.map(&:to_s)
309
- else raise NotImplementedError
310
- 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)
311
325
  else
312
326
  return maybe_raise Errors::InvalidTypeError, "function keys() expects a hash"
313
327
  end
@@ -323,10 +337,12 @@ module JMESPath
323
337
  def call(args)
324
338
  if args.count == 1
325
339
  value = args.first
326
- if hash_like?(value)
340
+ if value.respond_to?(:to_hash)
341
+ value.to_hash.values
342
+ elsif value.is_a?(Struct)
327
343
  value.values
328
- elsif Array === value
329
- value
344
+ elsif value.respond_to?(:to_ary)
345
+ value.to_ary
330
346
  else
331
347
  return maybe_raise Errors::InvalidTypeError, "function values() expects an array or a hash"
332
348
  end
@@ -343,10 +359,10 @@ module JMESPath
343
359
  if args.count == 2
344
360
  glue = args[0]
345
361
  values = args[1]
346
- if !(String === glue)
362
+ if !glue.respond_to?(:to_str)
347
363
  return maybe_raise Errors::InvalidTypeError, "function join() expects the first argument to be a string"
348
- elsif Array === values && values.all? { |v| String === v }
349
- 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)
350
366
  else
351
367
  return maybe_raise Errors::InvalidTypeError, "function join() expects values to be an array of strings"
352
368
  end
@@ -362,7 +378,7 @@ module JMESPath
362
378
  def call(args)
363
379
  if args.count == 1
364
380
  value = args.first
365
- String === value ? value : value.to_json
381
+ value.respond_to?(:to_str) ? value.to_str : value.to_json
366
382
  else
367
383
  return maybe_raise Errors::InvalidArityError, "function to_string() expects one argument"
368
384
  end
@@ -390,8 +406,8 @@ module JMESPath
390
406
  FUNCTIONS['sum'] = self
391
407
 
392
408
  def call(args)
393
- if args.count == 1 && Array === args.first
394
- 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|
395
411
  if Numeric === n
396
412
  sum + n
397
413
  else
@@ -424,7 +440,8 @@ module JMESPath
424
440
  def call(args)
425
441
  if args.count == 1
426
442
  value = args.first
427
- if Array === value
443
+ if value.respond_to?(:to_ary)
444
+ value = value.to_ary
428
445
  # every element in the list must be of the same type
429
446
  array_type = get_type(value[0])
430
447
  if array_type == STRING_TYPE || array_type == NUMBER_TYPE || value.size == 0
@@ -459,7 +476,7 @@ module JMESPath
459
476
  def call(args)
460
477
  if args.count == 2
461
478
  if get_type(args[0]) == ARRAY_TYPE && get_type(args[1]) == EXPRESSION_TYPE
462
- values = args[0]
479
+ values = args[0].to_ary
463
480
  expression = args[1]
464
481
  array_type = get_type(expression.eval(values[0]))
465
482
  if array_type == STRING_TYPE || array_type == NUMBER_TYPE || values.size == 0
@@ -495,6 +512,7 @@ module JMESPath
495
512
  values = args[0]
496
513
  expression = args[1]
497
514
  if get_type(values) == ARRAY_TYPE && get_type(expression) == EXPRESSION_TYPE
515
+ values = values.to_ary
498
516
  type = get_type(expression.eval(values.first))
499
517
  if type != NUMBER_TYPE && type != STRING_TYPE
500
518
  msg = "function #{mode}() expects values to be strings or numbers"
@@ -616,8 +634,10 @@ module JMESPath
616
634
  return maybe_raise Errors::InvalidArityError, msg
617
635
  end
618
636
  value = args.first
619
- if Array === value || String === value
620
- 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
621
641
  else
622
642
  msg = "function reverse() expects an array or string"
623
643
  return maybe_raise Errors::InvalidTypeError, msg
@@ -630,7 +650,7 @@ module JMESPath
630
650
 
631
651
  def call(args)
632
652
  value = args.first
633
- Array === value ? value : [value]
653
+ value.respond_to?(:to_ary) ? value.to_ary : [value]
634
654
  end
635
655
  end
636
656
  end
@@ -45,8 +45,8 @@ module JMESPath
45
45
 
46
46
  class ArrayProjection < Projection
47
47
  def extract_targets(target)
48
- if Array === target
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 hash_like?(target)
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
@@ -10,7 +10,7 @@ module JMESPath
10
10
  end
11
11
 
12
12
  def visit(value)
13
- if String === value || Array === value
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
- String === value ? result.join : result
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 String === value || Array === value
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
@@ -5,10 +5,6 @@ module JMESPath
5
5
  def visit(value)
6
6
  end
7
7
 
8
- def hash_like?(value)
9
- Hash === value || Struct === value
10
- end
11
-
12
8
  def optimize
13
9
  self
14
10
  end
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?(:empty?) && value.empty?) ||
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
@@ -1,3 +1,3 @@
1
1
  module JMESPath
2
- VERSION = '1.4.0'
2
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
3
3
  end
data/lib/jmespath.rb CHANGED
@@ -26,7 +26,7 @@ module JMESPath
26
26
  data = case data
27
27
  when Hash, Struct then data # check for most common case first
28
28
  when Pathname then load_json(data)
29
- when IO, StringIO then JSON.load(data.read)
29
+ when IO, StringIO then JSON.parse(data.read)
30
30
  else data
31
31
  end
32
32
  Runtime.new(runtime_options).search(expression, data)
@@ -34,7 +34,7 @@ module JMESPath
34
34
 
35
35
  # @api private
36
36
  def load_json(path)
37
- JSON.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
37
+ JSON.parse(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
38
38
  end
39
39
 
40
40
  end
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.0
4
+ version: 1.6.1
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: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2022-03-07 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
@@ -50,7 +51,7 @@ homepage: http://github.com/trevorrowe/jmespath.rb
50
51
  licenses:
51
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,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
68
  requirements: []
68
- rubyforge_project:
69
- rubygems_version: 2.5.1
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: []