jsonpath 0.9.2 → 0.9.3

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: 6fb42f9de5ec60194b2b37e99c6f1b511850d745
4
- data.tar.gz: 3a0191bf685d79146dc6ea6e7f89e4a30ec34ab6
2
+ SHA256:
3
+ metadata.gz: '048116fe74d7b281fbcf58d8f5d1aa44c359267bf179e58376527032e58c0094'
4
+ data.tar.gz: 4d91c8953e2750322d486f372b165507c4f383a42c11d07987cc49630abea5b6
5
5
  SHA512:
6
- metadata.gz: 856c7017b0b064a4cc658f38becbcd3caa0bc50627a063cc46b0b5a002675ddca8a95fef1b42b91df0b63a3f6faf8aaed9f402f646c77da743550c63168ec21b
7
- data.tar.gz: b660c60b66d4785f038629c2e47cad03d7e700a81d8b43c17cbdca0a75ce0908c55f8ac5b41f2aa6ec0cf62dc4edac9e2e2199151156b88d207aae8fd7744182
6
+ metadata.gz: fb899c515175b16b0f9c1001ae7525f14d086b4bf844779cef819c9e634511445c0ee1aa033c7e51c9419aa1de1e22ae8e4670e7fbaa162b27d5c819ebef0846
7
+ data.tar.gz: d303bb0188617e52133250571c43c0262b02cd1f586edb2d05683f30e6e26e17dfaeb81a3a62e40c4b838374e9b9354fbf012d03591fa7fb465549ff9148ddd8
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,112 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-07-07 21:29:45 +0200 using RuboCop version 0.57.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 15
10
+ # Configuration parameters: AllowSafeAssignment.
11
+ Lint/AssignmentInCondition:
12
+ Exclude:
13
+ - 'lib/jsonpath.rb'
14
+ - 'lib/jsonpath/parser.rb'
15
+
16
+ # Offense count: 1
17
+ Lint/IneffectiveAccessModifier:
18
+ Exclude:
19
+ - 'lib/jsonpath.rb'
20
+
21
+ # Offense count: 16
22
+ Metrics/AbcSize:
23
+ Max: 54
24
+
25
+ # Offense count: 2
26
+ # Configuration parameters: CountComments, ExcludedMethods.
27
+ Metrics/BlockLength:
28
+ Max: 33
29
+
30
+ # Offense count: 1
31
+ # Configuration parameters: CountBlocks.
32
+ Metrics/BlockNesting:
33
+ Max: 4
34
+
35
+ # Offense count: 2
36
+ # Configuration parameters: CountComments.
37
+ Metrics/ClassLength:
38
+ Max: 578
39
+
40
+ # Offense count: 6
41
+ Metrics/CyclomaticComplexity:
42
+ Max: 18
43
+
44
+ # Offense count: 24
45
+ # Configuration parameters: CountComments.
46
+ Metrics/MethodLength:
47
+ Max: 52
48
+
49
+ # Offense count: 1
50
+ # Configuration parameters: CountKeywordArgs.
51
+ Metrics/ParameterLists:
52
+ Max: 6
53
+
54
+ # Offense count: 6
55
+ Metrics/PerceivedComplexity:
56
+ Max: 20
57
+
58
+ # Offense count: 1
59
+ # Configuration parameters: AllowedChars.
60
+ Style/AsciiComments:
61
+ Exclude:
62
+ - 'lib/jsonpath/parser.rb'
63
+
64
+ # Offense count: 2
65
+ Style/Documentation:
66
+ Exclude:
67
+ - 'spec/**/*'
68
+ - 'test/**/*'
69
+ - 'lib/jsonpath/enumerable.rb'
70
+ - 'lib/jsonpath/proxy.rb'
71
+
72
+ # Offense count: 1
73
+ # Configuration parameters: MinBodyLength.
74
+ Style/GuardClause:
75
+ Exclude:
76
+ - 'lib/jsonpath/enumerable.rb'
77
+
78
+ # Offense count: 2
79
+ # Cop supports --auto-correct.
80
+ Style/IfUnlessModifier:
81
+ Exclude:
82
+ - 'lib/jsonpath/enumerable.rb'
83
+
84
+ # Offense count: 2
85
+ # Cop supports --auto-correct.
86
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
87
+ # SupportedStyles: predicate, comparison
88
+ Style/NumericPredicate:
89
+ Exclude:
90
+ - 'spec/**/*'
91
+ - 'lib/jsonpath/enumerable.rb'
92
+
93
+ # Offense count: 2
94
+ # Cop supports --auto-correct.
95
+ # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
96
+ # SupportedStyles: slashes, percent_r, mixed
97
+ Style/RegexpLiteral:
98
+ Exclude:
99
+ - 'lib/jsonpath/parser.rb'
100
+
101
+ # Offense count: 3
102
+ # Cop supports --auto-correct.
103
+ Style/RescueModifier:
104
+ Exclude:
105
+ - 'lib/jsonpath/enumerable.rb'
106
+ - 'lib/jsonpath/parser.rb'
107
+
108
+ # Offense count: 71
109
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
110
+ # URISchemes: http, https
111
+ Metrics/LineLength:
112
+ Max: 175
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 2.1.6
3
4
  - 2.3.1
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
  gemspec
3
- gem 'simplecov', :require => false, :group => :test
5
+ gem 'rubocop', require: true, group: :test
6
+ gem 'simplecov', require: false, group: :test
data/Rakefile CHANGED
@@ -1,3 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc 'run rubocop'
4
+ task(:rubocop) do
5
+ require 'rubocop'
6
+ cli = RuboCop::CLI.new
7
+ cli.run
8
+ end
9
+
1
10
  require 'simplecov'
2
11
  SimpleCov.start do
3
12
  add_filter '/test/'
@@ -11,4 +20,4 @@ task :test do
11
20
  Dir['./test/**/test_*.rb'].each { |test| require test }
12
21
  end
13
22
 
14
- task default: :test
23
+ task default: %i[test rubocop]
data/bin/jsonpath CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'jsonpath'
4
5
  require 'multi_json'
data/jsonpath.gemspec CHANGED
@@ -1,12 +1,14 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  require File.join(File.dirname(__FILE__), 'lib', 'jsonpath', 'version')
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'jsonpath'
7
7
  s.version = JsonPath::VERSION
8
- s.required_rubygems_version =
9
- Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
8
+ if s.respond_to? :required_rubygems_version=
9
+ s.required_rubygems_version =
10
+ Gem::Requirement.new('>= 0')
11
+ end
10
12
  s.authors = ['Joshua Hull', 'Gergely Brautigam']
11
13
  s.summary = 'Ruby implementation of http://goessner.net/articles/JsonPath/'
12
14
  s.description = 'Ruby implementation of http://goessner.net/articles/JsonPath/.'
@@ -25,10 +27,9 @@ Gem::Specification.new do |s|
25
27
  # dependencies
26
28
  s.add_runtime_dependency 'multi_json'
27
29
  s.add_runtime_dependency 'to_regexp', '~> 0.2.1'
30
+ s.add_development_dependency 'bundler'
28
31
  s.add_development_dependency 'code_stats'
29
- s.add_development_dependency 'rake'
30
32
  s.add_development_dependency 'minitest', '~> 2.2.0'
31
33
  s.add_development_dependency 'phocus'
32
- s.add_development_dependency 'bundler'
34
+ s.add_development_dependency 'rake'
33
35
  end
34
-
data/lib/jsonpath.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'strscan'
2
4
  require 'multi_json'
3
5
  require 'jsonpath/proxy'
@@ -8,7 +10,7 @@ require 'jsonpath/parser'
8
10
  # JsonPath: initializes the class with a given JsonPath and parses that path
9
11
  # into a token array.
10
12
  class JsonPath
11
- PATH_ALL = '$..*'.freeze
13
+ PATH_ALL = '$..*'
12
14
 
13
15
  attr_accessor :path
14
16
 
@@ -73,7 +75,7 @@ class JsonPath
73
75
  JsonPath::Enumerable.new(self, self.class.process_object(obj_or_str), mode,
74
76
  @opts)
75
77
  end
76
- alias_method :[], :enum_on
78
+ alias [] enum_on
77
79
 
78
80
  def self.on(obj_or_str, path, opts = {})
79
81
  new(path, opts).on(process_object(obj_or_str))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class JsonPath
2
4
  class Enumerable
3
5
  include ::Enumerable
@@ -32,7 +34,7 @@ class JsonPath
32
34
 
33
35
  private
34
36
 
35
- def handle_wildecard(node, expr, context, key, pos, &blk)
37
+ def handle_wildecard(node, expr, _context, _key, pos, &blk)
36
38
  expr[1, expr.size - 2].split(',').each do |sub_path|
37
39
  case sub_path[0]
38
40
  when '\'', '"'
@@ -60,27 +62,32 @@ class JsonPath
60
62
  end_idx %= node.size
61
63
  step = process_function_or_literal(array_args[2], 1)
62
64
  next unless step
63
- (start_idx..end_idx).step(step) { |i| each(node, i, pos + 1, &blk) }
65
+ if @mode == :delete
66
+ (start_idx..end_idx).step(step) { |i| node[i] = nil }
67
+ node.compact!
68
+ else
69
+ (start_idx..end_idx).step(step) { |i| each(node, i, pos + 1, &blk) }
70
+ end
64
71
  end
65
72
  end
66
73
  end
67
74
 
68
75
  def handle_question_mark(sub_path, node, pos, &blk)
69
76
  case node
70
- when Array
71
- node.size.times do |index|
72
- @_current_node = node[index]
73
- # exps = sub_path[1, sub_path.size - 1]
74
- # if @_current_node.send("[#{exps.gsub(/@/, '@_current_node')}]")
75
- if process_function_or_literal(sub_path[1, sub_path.size - 1])
76
- each(@_current_node, nil, pos + 1, &blk)
77
- end
78
- end
79
- when Hash
77
+ when Array
78
+ node.size.times do |index|
79
+ @_current_node = node[index]
80
+ # exps = sub_path[1, sub_path.size - 1]
81
+ # if @_current_node.send("[#{exps.gsub(/@/, '@_current_node')}]")
80
82
  if process_function_or_literal(sub_path[1, sub_path.size - 1])
81
83
  each(@_current_node, nil, pos + 1, &blk)
82
84
  end
83
- else
85
+ end
86
+ when Hash
87
+ if process_function_or_literal(sub_path[1, sub_path.size - 1])
88
+ each(@_current_node, nil, pos + 1, &blk)
89
+ end
90
+ else
84
91
  yield node if process_function_or_literal(sub_path[1, sub_path.size - 1])
85
92
  end
86
93
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'strscan'
2
4
  require 'to_regexp'
3
5
 
@@ -23,7 +25,7 @@ class JsonPath
23
25
  end
24
26
 
25
27
  def parse_exp(exp)
26
- exp = exp.sub(/@/, '').gsub(/^\(/, '').gsub(/\)$/, '').gsub(/"/, '\'').strip
28
+ exp = exp.sub(/@/, '').gsub(/^\(/, '').gsub(/\)$/, '').tr('"', '\'').strip
27
29
  scanner = StringScanner.new(exp)
28
30
  elements = []
29
31
  until scanner.eos?
@@ -39,25 +41,25 @@ class JsonPath
39
41
  operator = t
40
42
  elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/)
41
43
  # If we encounter a node which does not contain `'` it means
42
- # that we are dealing with a boolean type.
43
- if t == "true"
44
- operand = true
45
- elsif t == "false"
46
- operand = false
47
- else
48
- operand = operator.strip == "=~" ? t.to_regexp : t.delete("'").strip
49
- end
44
+ #  that we are dealing with a boolean type.
45
+ operand = if t == 'true'
46
+ true
47
+ elsif t == 'false'
48
+ false
49
+ else
50
+ operator.strip == '=~' ? t.to_regexp : t.delete("'").strip
51
+ end
50
52
  elsif t = scanner.scan(/\/\w+\//)
51
53
  elsif t = scanner.scan(/.*/)
52
54
  raise "Could not process symbol: #{t}"
53
55
  end
54
56
  end
55
57
 
56
- if elements.empty?
57
- el = @_current_node
58
- else
59
- el = dig(elements, @_current_node)
60
- end
58
+ el = if elements.empty?
59
+ @_current_node
60
+ else
61
+ dig(elements, @_current_node)
62
+ end
61
63
  return false if el.nil?
62
64
  return true if operator.nil? && el
63
65
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class JsonPath
2
4
  class Proxy
3
5
  attr_reader :obj
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class JsonPath
2
- VERSION = '0.9.2'.freeze
4
+ VERSION = '0.9.3'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'phocus'
3
5
  require 'jsonpath'
@@ -250,17 +252,17 @@ class TestJsonpath < MiniTest::Unit::TestCase
250
252
  end
251
253
 
252
254
  def test_support_at_sign_in_member_names
253
- assert_equal [@object['store']['@id']], JsonPath.new("$.store.@id").on(@object)
255
+ assert_equal [@object['store']['@id']], JsonPath.new('$.store.@id').on(@object)
254
256
  end
255
257
 
256
258
  def test_support_dollar_sign_in_member_names
257
259
  assert_equal [@object['store']['$meta-data']],
258
- JsonPath.new("$.store.$meta-data").on(@object)
260
+ JsonPath.new('$.store.$meta-data').on(@object)
259
261
  end
260
262
 
261
263
  def test_support_underscore_in_member_names
262
264
  assert_equal [@object['store']['_links']],
263
- JsonPath.new("$.store._links").on(@object)
265
+ JsonPath.new('$.store._links').on(@object)
264
266
  end
265
267
 
266
268
  def test_dig_return_string
@@ -271,12 +273,12 @@ class TestJsonpath < MiniTest::Unit::TestCase
271
273
  def test_slash_in_value
272
274
  data = {
273
275
  'data' => [{
274
- 'type' => 'mps/awesome',
275
- },{
276
- 'type' => 'not',
276
+ 'type' => 'mps/awesome'
277
+ }, {
278
+ 'type' => 'not'
277
279
  }]
278
280
  }
279
- assert_equal [{ 'type' => 'mps/awesome' }], JsonPath.new("$.data[?(@.type == \"mps/awesome\")]").on(data)
281
+ assert_equal [{ 'type' => 'mps/awesome' }], JsonPath.new('$.data[?(@.type == "mps/awesome")]').on(data)
280
282
  end
281
283
 
282
284
  def test_floating_point_with_precision_marker
@@ -285,7 +287,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
285
287
  'type' => 0.00001
286
288
  }
287
289
  }
288
- assert_equal [{"type"=>0.00001}], JsonPath.new("$.data[?(@.type == 0.00001)]").on(data)
290
+ assert_equal [{ 'type' => 0.00001 }], JsonPath.new('$.data[?(@.type == 0.00001)]').on(data)
289
291
  end
290
292
 
291
293
  def test_digits_only_string
@@ -295,7 +297,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
295
297
  'id' => '123'
296
298
  }
297
299
  }
298
- assert_equal([{"type"=>"users", "id"=>"123"}], JsonPath.new("$.foo[?(@.id == '123')]").on(data))
300
+ assert_equal([{ 'type' => 'users', 'id' => '123' }], JsonPath.new("$.foo[?(@.id == '123')]").on(data))
299
301
  end
300
302
 
301
303
  def test_digits_only_string_in_array
@@ -303,55 +305,55 @@ class TestJsonpath < MiniTest::Unit::TestCase
303
305
  'foo' => [{
304
306
  'type' => 'users',
305
307
  'id' => '123'
306
- },{
308
+ }, {
307
309
  'type' => 'users',
308
310
  'id' => '321'
309
311
  }]
310
312
  }
311
- assert_equal([{"type"=>"users", "id"=>"123"}], JsonPath.new("$.foo[?(@.id == '123')]").on(data))
313
+ assert_equal([{ 'type' => 'users', 'id' => '123' }], JsonPath.new("$.foo[?(@.id == '123')]").on(data))
312
314
  end
313
315
 
314
316
  def test_at_in_filter
315
317
  jsonld = {
316
- "mentions" => [
317
- {
318
- "name" => "Delimara Powerplant",
319
- "identifier" => "krzana://took/powerstation/Delimara Powerplant",
320
- "@type" => "Place",
321
- "geo" => {
322
- "latitude" => 35.83020073454,
323
- "longitude" => 14.55602645874
324
- }
325
- }
318
+ 'mentions' => [
319
+ {
320
+ 'name' => 'Delimara Powerplant',
321
+ 'identifier' => 'krzana://took/powerstation/Delimara Powerplant',
322
+ '@type' => 'Place',
323
+ 'geo' => {
324
+ 'latitude' => 35.83020073454,
325
+ 'longitude' => 14.55602645874
326
+ }
327
+ }
326
328
  ]
327
- }
328
- assert_equal(['Place'], JsonPath.new("$..mentions[?(@['@type'] == 'Place')].@type").on(jsonld))
329
+ }
330
+ assert_equal(['Place'], JsonPath.new("$..mentions[?(@['@type'] == 'Place')].@type").on(jsonld))
329
331
  end
330
332
 
331
333
  def test_dollar_in_filter
332
334
  jsonld = {
333
- "mentions" => [
334
- {
335
- "name" => "Delimara Powerplant",
336
- "identifier" => "krzana://took/powerstation/Delimara Powerplant",
337
- "$type" => "Place",
338
- "geo" => {
339
- "latitude" => 35.83020073454,
340
- "longitude" => 14.55602645874
341
- }
342
- }
335
+ 'mentions' => [
336
+ {
337
+ 'name' => 'Delimara Powerplant',
338
+ 'identifier' => 'krzana://took/powerstation/Delimara Powerplant',
339
+ '$type' => 'Place',
340
+ 'geo' => {
341
+ 'latitude' => 35.83020073454,
342
+ 'longitude' => 14.55602645874
343
+ }
344
+ }
343
345
  ]
344
- }
345
- assert_equal(['Place'], JsonPath.new("$..mentions[?(@['$type'] == 'Place')].$type").on(jsonld))
346
+ }
347
+ assert_equal(['Place'], JsonPath.new("$..mentions[?(@['$type'] == 'Place')].$type").on(jsonld))
346
348
  end
347
349
 
348
350
  def test_underscore_in_filter
349
351
  jsonld = {
350
- "attributes" => [
352
+ 'attributes' => [
351
353
  {
352
- "store" => [
353
- { "with" => "urn" },
354
- { "with_underscore" => "urn:1" }
354
+ 'store' => [
355
+ { 'with' => 'urn' },
356
+ { 'with_underscore' => 'urn:1' }
355
357
  ]
356
358
  }
357
359
  ]
@@ -361,18 +363,18 @@ class TestJsonpath < MiniTest::Unit::TestCase
361
363
 
362
364
  def test_at_in_value
363
365
  jsonld = {
364
- "mentions" =>
366
+ 'mentions' =>
365
367
  {
366
- "name" => "Delimara Powerplant",
367
- "identifier" => "krzana://took/powerstation/Delimara Powerplant",
368
- "type" => "@Place",
369
- "geo" => {
370
- "latitude" => 35.83020073454,
371
- "longitude" => 14.55602645874
372
- }
368
+ 'name' => 'Delimara Powerplant',
369
+ 'identifier' => 'krzana://took/powerstation/Delimara Powerplant',
370
+ 'type' => '@Place',
371
+ 'geo' => {
372
+ 'latitude' => 35.83020073454,
373
+ 'longitude' => 14.55602645874
374
+ }
373
375
  }
374
- }
375
- assert_equal(['@Place'], JsonPath.new("$..mentions.type[?(@ == '@Place')]").on(jsonld))
376
+ }
377
+ assert_equal(['@Place'], JsonPath.new("$..mentions.type[?(@ == '@Place')]").on(jsonld))
376
378
  end
377
379
 
378
380
  def test_parens_in_value
@@ -381,21 +383,20 @@ class TestJsonpath < MiniTest::Unit::TestCase
381
383
  'number' => '(492) 080-3961'
382
384
  }
383
385
  }
384
- assert_equal [{'number'=>'(492) 080-3961'}], JsonPath.new("$.data[?(@.number == '(492) 080-3961')]").on(data)
386
+ assert_equal [{ 'number' => '(492) 080-3961' }], JsonPath.new("$.data[?(@.number == '(492) 080-3961')]").on(data)
385
387
  end
386
388
 
387
-
388
389
  def test_boolean_parameter_value
389
390
  data = {
390
391
  'data' => [{
391
392
  'isTrue' => true,
392
- 'name' => 'testname1',
393
- },{
393
+ 'name' => 'testname1'
394
+ }, {
394
395
  'isTrue' => false,
395
- 'name' => 'testname2',
396
- }]
396
+ 'name' => 'testname2'
397
+ }]
397
398
  }
398
- assert_equal [{"isTrue"=>true, "name"=>"testname1"}], JsonPath.new("$.data[?(@.isTrue)]").on(data)
399
+ assert_equal [{ 'isTrue' => true, 'name' => 'testname1' }], JsonPath.new('$.data[?(@.isTrue)]').on(data)
399
400
  end
400
401
 
401
402
  def test_regex
@@ -404,9 +405,9 @@ class TestJsonpath < MiniTest::Unit::TestCase
404
405
  @object['store']['book'][2],
405
406
  @object['store']['book'][4],
406
407
  @object['store']['book'][5],
407
- @object['store']['book'][6],
408
+ @object['store']['book'][6]
408
409
  ], JsonPath.new('$..book[?(@.author =~ /herman|lukyanenko/i)]').on(@object)
409
- assert_equal ["asdf", "asdf2"], JsonPath.new("$.store.book..tags[?(@ =~ /asdf/)]").on(@object)
410
+ assert_equal %w[asdf asdf2], JsonPath.new('$.store.book..tags[?(@ =~ /asdf/)]').on(@object)
410
411
  end
411
412
 
412
413
  def test_regression_1
@@ -444,7 +445,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
444
445
  ]
445
446
  }.to_json
446
447
 
447
- assert_equal 'C09C5GYHF', JsonPath.on(json, "$..channels[?(@.is_archived == false)].id")[0]
448
+ assert_equal 'C09C5GYHF', JsonPath.on(json, '$..channels[?(@.is_archived == false)].id')[0]
448
449
  end
449
450
 
450
451
  def test_regression_3
@@ -464,7 +465,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
464
465
  ]
465
466
  }.to_json
466
467
 
467
- assert_equal 'C09C598QL', JsonPath.on(json, "$..channels[?(@.is_archived)].id")[0]
468
+ assert_equal 'C09C598QL', JsonPath.on(json, '$..channels[?(@.is_archived)].id')[0]
468
469
  end
469
470
 
470
471
  def test_regression_4
@@ -509,26 +510,26 @@ class TestJsonpath < MiniTest::Unit::TestCase
509
510
 
510
511
  def test_changed
511
512
  json =
512
- {
513
- "snapshot"=> {
514
- "objects"=> {
515
- "whatever"=> [
516
- {
517
- "column"=> {
518
- "name"=> "ASSOCIATE_FLAG",
519
- "nullable"=> true
520
- }
521
- },
522
- {
523
- "column"=> {
524
- "name"=> "AUTHOR",
525
- "nullable"=> false
513
+ {
514
+ 'snapshot' => {
515
+ 'objects' => {
516
+ 'whatever' => [
517
+ {
518
+ 'column' => {
519
+ 'name' => 'ASSOCIATE_FLAG',
520
+ 'nullable' => true
521
+ }
522
+ },
523
+ {
524
+ 'column' => {
525
+ 'name' => 'AUTHOR',
526
+ 'nullable' => false
527
+ }
526
528
  }
527
- }
528
- ]
529
+ ]
530
+ }
529
531
  }
530
532
  }
531
- }
532
533
  assert_equal true, JsonPath.on(json, "$..column[?(@.name == 'ASSOCIATE_FLAG')].nullable")[0]
533
534
  end
534
535
 
@@ -537,30 +538,75 @@ class TestJsonpath < MiniTest::Unit::TestCase
537
538
  initial: true,
538
539
  not: true
539
540
  }.to_json
540
- assert_equal [{"initial"=>true, "not"=>true}], JsonPath.on(json, "$.[?(@.initial == true)]")
541
+ assert_equal [{ 'initial' => true, 'not' => true }], JsonPath.on(json, '$.[?(@.initial == true)]')
541
542
  json = {
542
543
  initial: false,
543
544
  not: true
544
545
  }.to_json
545
- assert_equal [], JsonPath.on(json, "$.initial[?(@)]")
546
- assert_equal [], JsonPath.on(json, "$.[?(@.initial == true)]")
547
- assert_equal [{"initial"=>false, "not"=>true}], JsonPath.on(json, "$.[?(@.initial == false)]")
546
+ assert_equal [], JsonPath.on(json, '$.initial[?(@)]')
547
+ assert_equal [], JsonPath.on(json, '$.[?(@.initial == true)]')
548
+ assert_equal [{ 'initial' => false, 'not' => true }], JsonPath.on(json, '$.[?(@.initial == false)]')
548
549
  json = {
549
550
  initial: 'false',
550
551
  not: true
551
552
  }.to_json
552
- assert_equal [{"initial"=>"false", "not"=>true}], JsonPath.on(json, "$.[?(@.initial == 'false')]")
553
- assert_equal [], JsonPath.on(json, "$.[?(@.initial == false)]")
553
+ assert_equal [{ 'initial' => 'false', 'not' => true }], JsonPath.on(json, "$.[?(@.initial == 'false')]")
554
+ assert_equal [], JsonPath.on(json, '$.[?(@.initial == false)]')
554
555
  end
555
556
 
556
557
  def test_hanging
557
558
  json = { initial: true }.to_json
558
- success_path = "$.initial"
559
+ success_path = '$.initial'
559
560
  assert_equal [true], JsonPath.on(json, success_path)
560
561
  broken_path = "$.initial\n"
561
562
  assert_equal [true], JsonPath.on(json, broken_path)
562
563
  end
563
564
 
565
+ def test_delete_more_items
566
+ a = { 'itemList' =>
567
+ [{ 'alfa' => 'beta1' },
568
+ { 'alfa' => 'beta2' },
569
+ { 'alfa' => 'beta3' },
570
+ { 'alfa' => 'beta4' },
571
+ { 'alfa' => 'beta5' },
572
+ { 'alfa' => 'beta6' },
573
+ { 'alfa' => 'beta7' },
574
+ { 'alfa' => 'beta8' },
575
+ { 'alfa' => 'beta9' },
576
+ { 'alfa' => 'beta10' },
577
+ { 'alfa' => 'beta11' },
578
+ { 'alfa' => 'beta12' }] }
579
+ expected = { 'itemList' => [{ 'alfa' => 'beta1' }] }
580
+ assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:11:1]').to_hash
581
+ end
582
+
583
+ def test_delete_more_items_with_stepping
584
+ a = { 'itemList' =>
585
+ [{ 'alfa' => 'beta1' },
586
+ { 'alfa' => 'beta2' },
587
+ { 'alfa' => 'beta3' },
588
+ { 'alfa' => 'beta4' },
589
+ { 'alfa' => 'beta5' },
590
+ { 'alfa' => 'beta6' },
591
+ { 'alfa' => 'beta7' },
592
+ { 'alfa' => 'beta8' },
593
+ { 'alfa' => 'beta9' },
594
+ { 'alfa' => 'beta10' },
595
+ { 'alfa' => 'beta11' },
596
+ { 'alfa' => 'beta12' }] }
597
+ expected = { 'itemList' =>
598
+ [{ 'alfa' => 'beta1' },
599
+ { 'alfa' => 'beta3' },
600
+ { 'alfa' => 'beta5' },
601
+ { 'alfa' => 'beta7' },
602
+ { 'alfa' => 'beta8' },
603
+ { 'alfa' => 'beta9' },
604
+ { 'alfa' => 'beta10' },
605
+ { 'alfa' => 'beta11' },
606
+ { 'alfa' => 'beta12' }] }
607
+ assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:6:2]').to_hash
608
+ end
609
+
564
610
  def example_object
565
611
  { 'store' => {
566
612
  'book' => [
@@ -568,7 +614,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
568
614
  'author' => 'Nigel Rees',
569
615
  'title' => 'Sayings of the Century',
570
616
  'price' => 9,
571
- 'tags' => ['asdf', 'asdf2']},
617
+ 'tags' => %w[asdf asdf2] },
572
618
  { 'category' => 'fiction',
573
619
  'author' => 'Evelyn Waugh',
574
620
  'title' => 'Sword of Honour',
@@ -610,9 +656,9 @@ class TestJsonpath < MiniTest::Unit::TestCase
610
656
  '2seater' => 'yes',
611
657
  'make:model' => 'Zippy Sweetwheeler'
612
658
  },
613
- "@id" => "http://example.org/store/42",
614
- "$meta-data" => "whatevs",
615
- "_links" => { "self" => {} }
659
+ '@id' => 'http://example.org/store/42',
660
+ '$meta-data' => 'whatevs',
661
+ '_links' => { 'self' => {} }
616
662
  } }
617
663
  end
618
664
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'phocus'
3
5
  require 'jsonpath'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-14 00:00:00.000000000 Z
12
+ date: 2018-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.2.1
42
42
  - !ruby/object:Gem::Dependency
43
- name: code_stats
43
+ name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rake
57
+ name: code_stats
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: bundler
99
+ name: rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -122,6 +122,8 @@ files:
122
122
  - ".gemtest"
123
123
  - ".gitignore"
124
124
  - ".rspec"
125
+ - ".rubocop.yml"
126
+ - ".rubocop_todo.yml"
125
127
  - ".travis.yml"
126
128
  - Gemfile
127
129
  - LICENSE.md
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  version: '0'
158
160
  requirements: []
159
161
  rubyforge_project: jsonpath
160
- rubygems_version: 2.6.12
162
+ rubygems_version: 2.7.3
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: Ruby implementation of http://goessner.net/articles/JsonPath/