jsonpath 0.9.0 → 0.9.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
2
  SHA1:
3
- metadata.gz: 02b522c0db894285a626b8e1d6d44a95140d5a03
4
- data.tar.gz: 1f4176316390136b0d229627bf3965f4b4ae1c44
3
+ metadata.gz: aa8657a28248b15d9ae03ef56bbfa2a436fec517
4
+ data.tar.gz: 41e9c32a10b1e26423b7833cb547f2d475798225
5
5
  SHA512:
6
- metadata.gz: 7f4e322af2377394c35ca7fa5fb03f3f3df63ed815eb064d33c6a4e96064ad872a3fc58a3462ecffa4f733d7444d484abb4a454e4b0bb75dbea1cce0f3ad57be
7
- data.tar.gz: 72110c129177b94eb9572bc4dd288dfe6bd8025f00db6c71ef4b384b0122f9ba6d373c7305fce7c6e477b50a524fc2b921c33bd95eb01877c752758a074d7378
6
+ metadata.gz: b505037a9c8d5d7cf2be89838edb95a7f2ac31f097b8ff81c9c16b7b6205ce49cf19c4e297cb4a83be48b1dbcc026c85ae875c9bd93b7b40a888c09714e58a2b
7
+ data.tar.gz: 65a6f59db06dac30434fbf113f12476ef7c944b47589cceee468e4984566ce8157d7730d91e43d1d6d3d639995337eae3065ef715ec2a8e362e260f71c8c5a41
data/lib/jsonpath.rb CHANGED
@@ -14,7 +14,7 @@ class JsonPath
14
14
 
15
15
  def initialize(path, opts = nil)
16
16
  @opts = opts
17
- scanner = StringScanner.new(path)
17
+ scanner = StringScanner.new(path.strip)
18
18
  @path = []
19
19
  until scanner.eos?
20
20
  if token = scanner.scan(/\$\B|@\B|\*|\.\./)
@@ -66,14 +66,20 @@ class JsonPath
66
66
 
67
67
  def handle_question_mark(sub_path, node, pos, &blk)
68
68
  case node
69
- when Hash, Array
70
- (node.is_a?(Hash) ? node.keys : (0..node.size)).each do |e|
71
- @_current_node = node[e]
69
+ when Array
70
+ node.size.times do |index|
71
+ @_current_node = node[index]
72
+ # exps = sub_path[1, sub_path.size - 1]
73
+ # if @_current_node.send("[#{exps.gsub(/@/, '@_current_node')}]")
74
+ if process_function_or_literal(sub_path[1, sub_path.size - 1])
75
+ each(@_current_node, nil, pos + 1, &blk)
76
+ end
77
+ end
78
+ when Hash
72
79
  if process_function_or_literal(sub_path[1, sub_path.size - 1])
73
80
  each(@_current_node, nil, pos + 1, &blk)
74
81
  end
75
- end
76
- else
82
+ else
77
83
  yield node if process_function_or_literal(sub_path[1, sub_path.size - 1])
78
84
  end
79
85
  end
@@ -1,3 +1,3 @@
1
1
  class JsonPath
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.9.1'.freeze
3
3
  end
@@ -245,7 +245,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
245
245
  'id' => '123'
246
246
  }
247
247
  }
248
- assert_equal [{ 'type' => 'users', 'id' => '123' }], JsonPath.new("$.[?(@.type == 'users')]").on(data)
248
+ assert_equal [{ 'type' => 'users', 'id' => '123' }], JsonPath.new("$.data[?(@.type == 'users')]").on(data)
249
249
  assert_equal [], JsonPath.new("$.[?(@.type == 'admins')]").on(data)
250
250
  end
251
251
 
@@ -285,7 +285,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
285
285
  'type' => 0.00001
286
286
  }
287
287
  }
288
- assert_equal [{"type"=>0.00001}], JsonPath.new("$.[?(@.type == 0.00001)]").on(data)
288
+ assert_equal [{"type"=>0.00001}], JsonPath.new("$.data[?(@.type == 0.00001)]").on(data)
289
289
  end
290
290
 
291
291
  def test_digits_only_string
@@ -295,7 +295,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
295
295
  'id' => '123'
296
296
  }
297
297
  }
298
- assert_equal([{"type"=>"users", "id"=>"123"}], JsonPath.new("$.[?(@.id == '123')]").on(data))
298
+ assert_equal([{"type"=>"users", "id"=>"123"}], JsonPath.new("$.foo[?(@.id == '123')]").on(data))
299
299
  end
300
300
 
301
301
  def test_digits_only_string_in_array
@@ -381,7 +381,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
381
381
  'number' => '(492) 080-3961'
382
382
  }
383
383
  }
384
- assert_equal [{'number'=>'(492) 080-3961'}], JsonPath.new("$.[?(@.number == '(492) 080-3961')]").on(data)
384
+ assert_equal [{'number'=>'(492) 080-3961'}], JsonPath.new("$.data[?(@.number == '(492) 080-3961')]").on(data)
385
385
  end
386
386
 
387
387
 
@@ -484,7 +484,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
484
484
  ]
485
485
  }.to_json
486
486
 
487
- assert_equal ['C09C5GYHF'], JsonPath.on(json, "$..[?(@.name == 'general')].id")
487
+ assert_equal ['C09C5GYHF'], JsonPath.on(json, "$..channels[?(@.name == 'general')].id")
488
488
  end
489
489
 
490
490
  def test_regression_5
@@ -507,6 +507,52 @@ class TestJsonpath < MiniTest::Unit::TestCase
507
507
  assert_equal 'C09C5GYHF', JsonPath.on(json, "$..channels[?(@.is_archived == 'false')].id")[0]
508
508
  end
509
509
 
510
+ def test_changed
511
+ 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
526
+ }
527
+ }
528
+ ]
529
+ }
530
+ }
531
+ }
532
+ assert_equal true, JsonPath.on(json, "$..column[?(@.name == 'ASSOCIATE_FLAG')].nullable")[0]
533
+ end
534
+
535
+ def test_another
536
+ json = {
537
+ initial: true,
538
+ not: true
539
+ }.to_json
540
+ assert_equal [true], JsonPath.on(json, "$.initial[?(@)]")
541
+ json = {
542
+ initial: false,
543
+ not: true
544
+ }.to_json
545
+ assert_equal [], JsonPath.on(json, "$.initial[?(@)]")
546
+ end
547
+
548
+ def test_hanging
549
+ json = { initial: true }.to_json
550
+ success_path = "$.initial"
551
+ assert_equal [true], JsonPath.on(json, success_path)
552
+ broken_path = "$.initial\n"
553
+ assert_equal [true], JsonPath.on(json, broken_path)
554
+ end
555
+
510
556
  def example_object
511
557
  { 'store' => {
512
558
  'book' => [
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.0
4
+ version: 0.9.1
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-05-13 00:00:00.000000000 Z
12
+ date: 2018-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project: jsonpath
160
- rubygems_version: 2.6.12
160
+ rubygems_version: 2.6.14
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Ruby implementation of http://goessner.net/articles/JsonPath/