jmespath 1.5.0 → 1.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 802d17af3f269cfbd38879ff753082257effba66f383f415667b1018d9d68c5c
4
- data.tar.gz: 3b9ec8bf65b3dbcf00273667510385a406fa2c23cd64890557a76263944a8b0f
3
+ metadata.gz: e9276a9f614d19179d10e5e166950070fdbce091b7154ea2c15e700ca155ab4e
4
+ data.tar.gz: e3a122d91c10056382b50876583f550be0bf07a015c68ffaaff8cb2c3e4fcacf
5
5
  SHA512:
6
- metadata.gz: c95fe346be9e1e36a67869cad050a03e74ae414ceedb09049210419a9d4c5455df38e49403bcedf1434b56e8b45d6142527bdb3d2af86919cc833da021251e16
7
- data.tar.gz: 73e3c073ccf6b57c65c2246d12fd4a3c5d5f3beb603772966c4ec92371f9ed10f4e1a10b66a1619f50fdd78137a1a6b0998f65b4e7f966a928e5fc2a8d7393be
6
+ metadata.gz: 46128b4ab5e58de1f2cdcb80a2b2e8e69690cce7455da154da4b4c18406e80a83de24c07339eca4cddef142afea29b74f131b48fe7292ce36131b8e2cd1cb80c
7
+ data.tar.gz: 0f44933d7fc3736bf71273736089b7c6787ce4127f96742b263822a7eb7123e9326f7a9512b408d9128bdd0fb6dcf8839ddceaf773c75f031c1c65436929ee42
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
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,6 +38,12 @@ 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
@@ -54,7 +62,7 @@ module JMESPath
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,6 +38,14 @@ 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
@@ -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
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.5.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Rowe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-10 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
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.2.7
69
+ rubygems_version: 3.2.3
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: JMESPath - Ruby Edition