jmespath 1.6.0 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,28 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
 
3
4
  module JMESPath
4
5
  # @api private
5
6
  class Parser
6
-
7
7
  AFTER_DOT = Set.new([
8
- Lexer::T_IDENTIFIER, # foo.bar
9
- Lexer::T_QUOTED_IDENTIFIER, # foo."bar"
10
- Lexer::T_STAR, # foo.*
11
- Lexer::T_LBRACE, # foo{a: 0}
12
- Lexer::T_LBRACKET, # foo[1]
13
- Lexer::T_FILTER, # foo.[?bar==10]
14
- ])
8
+ Lexer::T_IDENTIFIER, # foo.bar
9
+ Lexer::T_QUOTED_IDENTIFIER, # foo."bar"
10
+ Lexer::T_STAR, # foo.*
11
+ Lexer::T_LBRACE, # foo{a: 0}
12
+ Lexer::T_LBRACKET, # foo[1]
13
+ Lexer::T_FILTER, # foo.[?bar==10]
14
+ ])
15
15
 
16
16
  NUM_COLON_RBRACKET = Set.new([
17
- Lexer::T_NUMBER,
18
- Lexer::T_COLON,
19
- Lexer::T_RBRACKET,
20
- ])
17
+ Lexer::T_NUMBER,
18
+ Lexer::T_COLON,
19
+ Lexer::T_RBRACKET
20
+ ])
21
21
 
22
22
  COLON_RBRACKET = Set.new([
23
- Lexer::T_COLON,
24
- Lexer::T_RBRACKET,
25
- ])
23
+ Lexer::T_COLON,
24
+ Lexer::T_RBRACKET
25
+ ])
26
26
 
27
27
  CURRENT_NODE = Nodes::Current.new
28
28
 
@@ -34,7 +34,7 @@ module JMESPath
34
34
 
35
35
  # @param [String<JMESPath>] expression
36
36
  def parse(expression)
37
- tokens = @lexer.tokenize(expression)
37
+ tokens = @lexer.tokenize(expression)
38
38
  stream = TokenStream.new(expression, tokens)
39
39
  result = expr(stream)
40
40
  if stream.token.type != Lexer::T_EOF
@@ -110,13 +110,11 @@ module JMESPath
110
110
 
111
111
  def nud_lbrace(stream)
112
112
  valid_keys = Set.new([:quoted_identifier, :identifier])
113
- stream.next(match:valid_keys)
113
+ stream.next(match: valid_keys)
114
114
  pairs = []
115
115
  begin
116
116
  pairs << parse_key_value_pair(stream)
117
- if stream.token.type == :comma
118
- stream.next(match:valid_keys)
119
- end
117
+ stream.next(match: valid_keys) if stream.token.type == :comma
120
118
  end while stream.token.type != :rbrace
121
119
  stream.next
122
120
  Nodes::MultiSelectHash.new(pairs)
@@ -167,7 +165,7 @@ module JMESPath
167
165
  end
168
166
 
169
167
  def led_dot(stream, left)
170
- stream.next(match:AFTER_DOT)
168
+ stream.next(match: AFTER_DOT)
171
169
  if stream.token.type == :star
172
170
  parse_wildcard_object(stream, left)
173
171
  else
@@ -217,12 +215,10 @@ module JMESPath
217
215
  stream.next
218
216
  while stream.token.type != :rparen
219
217
  args << expr(stream, 0)
220
- if stream.token.type == :comma
221
- stream.next
222
- end
218
+ stream.next if stream.token.type == :comma
223
219
  end
224
220
  stream.next
225
- Nodes::Function.create(name, args, :disable_visit_errors => @disable_visit_errors)
221
+ Nodes::Function.create(name, args, disable_visit_errors: @disable_visit_errors)
226
222
  end
227
223
 
228
224
  def led_or(stream, left)
@@ -286,7 +282,7 @@ module JMESPath
286
282
 
287
283
  def parse_key_value_pair(stream)
288
284
  key = stream.token.value
289
- stream.next(match:Set.new([:colon]))
285
+ stream.next(match: Set.new([:colon]))
290
286
  stream.next
291
287
  Nodes::MultiSelectHash::KeyValuePair.new(key, expr(stream))
292
288
  end
@@ -311,7 +307,7 @@ module JMESPath
311
307
  if stream.token.binding_power < 10
312
308
  CURRENT_NODE
313
309
  elsif type == :dot
314
- stream.next(match:AFTER_DOT)
310
+ stream.next(match: AFTER_DOT)
315
311
  parse_dot(stream, binding_power)
316
312
  elsif type == :lbracket || type == :filter
317
313
  expr(stream, binding_power)
@@ -321,7 +317,7 @@ module JMESPath
321
317
  end
322
318
 
323
319
  def parse_wildcard_array(stream, left = nil)
324
- stream.next(match:Set.new([:rbracket]))
320
+ stream.next(match: Set.new([:rbracket]))
325
321
  stream.next
326
322
  left ||= CURRENT_NODE
327
323
  right = parse_projection(stream, Token::BINDING_POWER[:star])
@@ -334,6 +330,5 @@ module JMESPath
334
330
  right = parse_projection(stream, Token::BINDING_POWER[:star])
335
331
  Nodes::ObjectProjection.new(left, right)
336
332
  end
337
-
338
333
  end
339
334
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module JMESPath
2
3
  # @api private
3
4
  class Runtime
4
-
5
5
  # @api private
6
6
  DEFAULT_PARSER = CachingParser
7
7
 
@@ -66,6 +66,5 @@ module JMESPath
66
66
  DEFAULT_PARSER.new(options)
67
67
  end
68
68
  end
69
-
70
69
  end
71
70
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module JMESPath
2
3
  # @api private
3
4
  class Token < Struct.new(:type, :value, :position, :binding_power)
4
-
5
5
  NULL_TOKEN = Token.new(:eof, '', nil)
6
6
 
7
7
  BINDING_POWER = {
@@ -28,8 +28,8 @@ module JMESPath
28
28
  Lexer::T_NOT => 45,
29
29
  Lexer::T_LBRACE => 50,
30
30
  Lexer::T_LBRACKET => 55,
31
- Lexer::T_LPAREN => 60,
32
- }
31
+ Lexer::T_LPAREN => 60
32
+ }.freeze
33
33
 
34
34
  # @param [Symbol] type
35
35
  # @param [Mixed] value
@@ -37,6 +37,5 @@ module JMESPath
37
37
  def initialize(type, value, position)
38
38
  super(type, value, position, BINDING_POWER[type])
39
39
  end
40
-
41
40
  end
42
41
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module JMESPath
2
3
  # @api private
3
4
  class TokenStream
4
-
5
5
  # @param [String<JMESPath>] expression
6
6
  # @param [Array<Token>] tokens
7
7
  def initialize(expression, tokens)
@@ -35,8 +35,8 @@ module JMESPath
35
35
  def inspect
36
36
  str = []
37
37
  @tokens.each do |token|
38
- str << "%3d %-15s %s" %
39
- [token.position, token.type, token.value.inspect]
38
+ str << '%3d %-15s %s' %
39
+ [token.position, token.type, token.value.inspect]
40
40
  end
41
41
  str.join("\n")
42
42
  end
@@ -50,11 +50,10 @@ module JMESPath
50
50
 
51
51
  def validate_match(token, match)
52
52
  if match && !match.include?(token.type)
53
- raise Errors::SyntaxError, "type missmatch"
53
+ raise Errors::SyntaxError, 'type missmatch'
54
54
  else
55
55
  token
56
56
  end
57
57
  end
58
-
59
58
  end
60
59
  end
data/lib/jmespath/util.rb CHANGED
@@ -1,18 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  module JMESPath
2
3
  # @api private
3
4
  module Util
4
5
  class << self
5
-
6
6
  # Determines if a value is false as defined by JMESPath:
7
7
  #
8
8
  # https://github.com/jmespath/jmespath.site/blob/master/docs/proposals/improved-filters.rst#and-expressions-1
9
9
  #
10
10
  def falsey?(value)
11
11
  !value ||
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?) ||
15
- (value.respond_to?(:entries) && !value.entries.any?)
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?) ||
15
+ (value.respond_to?(:entries) && !value.entries.any?)
16
16
  # final case necessary to support Enumerable and Struct
17
17
  end
18
18
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module JMESPath
2
3
  VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
3
4
  end
data/lib/jmespath.rb CHANGED
@@ -1,9 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'json'
2
3
  require 'stringio'
3
4
  require 'pathname'
4
5
 
5
6
  module JMESPath
6
-
7
7
  require 'jmespath/caching_parser'
8
8
  require 'jmespath/errors'
9
9
  require 'jmespath/lexer'
@@ -16,7 +16,6 @@ module JMESPath
16
16
  require 'jmespath/version'
17
17
 
18
18
  class << self
19
-
20
19
  # @param [String] expression A valid
21
20
  # [JMESPath](https://github.com/boto/jmespath) expression.
22
21
  # @param [Hash] data
@@ -24,18 +23,17 @@ module JMESPath
24
23
  # expression does not resolve inside `data`.
25
24
  def search(expression, data, runtime_options = {})
26
25
  data = case data
27
- when Hash, Struct then data # check for most common case first
28
- when Pathname then load_json(data)
29
- when IO, StringIO then JSON.load(data.read)
30
- else data
26
+ when Hash, Struct then data # check for most common case first
27
+ when Pathname then load_json(data)
28
+ when IO, StringIO then JSON.parse(data.read)
29
+ else data
31
30
  end
32
31
  Runtime.new(runtime_options).search(expression, data)
33
32
  end
34
33
 
35
34
  # @api private
36
35
  def load_json(path)
37
- JSON.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
36
+ JSON.parse(File.open(path, 'r', encoding: 'UTF-8', &:read))
38
37
  end
39
-
40
38
  end
41
39
  end
metadata CHANGED
@@ -1,23 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jmespath
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.2
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-02-14 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implements JMESPath for Ruby
14
14
  email: trevorrowe@gmail.com
15
- executables: []
15
+ executables:
16
+ - jmespath.rb
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
20
  - LICENSE.txt
20
21
  - VERSION
22
+ - bin/jmespath.rb
21
23
  - lib/jmespath.rb
22
24
  - lib/jmespath/caching_parser.rb
23
25
  - lib/jmespath/errors.rb
@@ -66,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  - !ruby/object:Gem::Version
67
69
  version: '0'
68
70
  requirements: []
69
- rubygems_version: 3.2.3
71
+ rubygems_version: 3.2.22
70
72
  signing_key:
71
73
  specification_version: 4
72
74
  summary: JMESPath - Ruby Edition