jsonpath 0.9.7 → 0.9.8
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 +4 -4
- data/lib/jsonpath/enumerable.rb +11 -1
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a93fe71b722f53a4e02e2ea53e98a98acb281f09
|
4
|
+
data.tar.gz: afad26b3e7d0ff73db16afe367103562fc3324f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e680652eaffb4d056c69038cf3abceaebc94c37de6f987aa2e0923c65bd9c7ff3c0609ce6fcbcafa0a2406ca333318d4353bbe2920c5df4d6e13820c9f49e237
|
7
|
+
data.tar.gz: 10f6f6dd70bc861974141cb9c8eff68f3da85958ca5efc8df98679ce291bb0788c997156180b5231b37f7d36f2e9caba1bbcfb87dfcf2fb7a3b3f24d49410d29
|
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -51,10 +51,14 @@ class JsonPath
|
|
51
51
|
if array_args[0] == '*'
|
52
52
|
start_idx = 0
|
53
53
|
end_idx = node.size - 1
|
54
|
+
elsif sub_path.count(':') == 0
|
55
|
+
start_idx = end_idx = process_function_or_literal(array_args[0], 0)
|
56
|
+
next unless start_idx
|
57
|
+
next if start_idx >= node.size
|
54
58
|
else
|
55
59
|
start_idx = process_function_or_literal(array_args[0], 0)
|
56
60
|
next unless start_idx
|
57
|
-
end_idx =
|
61
|
+
end_idx = array_args[1] && ensure_exclusive_end_index(process_function_or_literal(array_args[1], -1)) || -1
|
58
62
|
next unless end_idx
|
59
63
|
next if start_idx == end_idx && start_idx >= node.size
|
60
64
|
end
|
@@ -72,6 +76,12 @@ class JsonPath
|
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
79
|
+
def ensure_exclusive_end_index(value)
|
80
|
+
return value unless value.is_a?(Integer) && value > 0
|
81
|
+
|
82
|
+
value - 1
|
83
|
+
end
|
84
|
+
|
75
85
|
def handle_question_mark(sub_path, node, pos, &blk)
|
76
86
|
case node
|
77
87
|
when Array
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -48,13 +48,18 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_recognize_array_splices
|
51
|
-
assert_equal [@object['store']['book'][0]
|
51
|
+
assert_equal [@object['store']['book'][0]], JsonPath.new('$..book[0:1:1]').on(@object)
|
52
|
+
assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0:2:1]').on(@object)
|
52
53
|
assert_equal [@object['store']['book'][1], @object['store']['book'][3], @object['store']['book'][5]], JsonPath.new('$..book[1::2]').on(@object)
|
53
54
|
assert_equal [@object['store']['book'][0], @object['store']['book'][2], @object['store']['book'][4], @object['store']['book'][6]], JsonPath.new('$..book[::2]').on(@object)
|
54
55
|
assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new('$..book[:-5:2]').on(@object)
|
55
56
|
assert_equal [@object['store']['book'][5], @object['store']['book'][6]], JsonPath.new('$..book[5::]').on(@object)
|
56
57
|
end
|
57
58
|
|
59
|
+
def test_slice_array_with_exclusive_end_correctly
|
60
|
+
assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[:2]').on(@object)
|
61
|
+
end
|
62
|
+
|
58
63
|
def test_recognize_array_comma
|
59
64
|
assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0,1]').on(@object)
|
60
65
|
assert_equal [@object['store']['book'][2], @object['store']['book'][6]], JsonPath.new('$..book[2,-1::]').on(@object)
|
@@ -722,7 +727,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
722
727
|
{ 'alfa' => 'beta11' },
|
723
728
|
{ 'alfa' => 'beta12' }] }
|
724
729
|
expected = { 'itemList' => [{ 'alfa' => 'beta1' }] }
|
725
|
-
assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:
|
730
|
+
assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:12:1]').to_hash
|
726
731
|
end
|
727
732
|
|
728
733
|
def test_delete_more_items_with_stepping
|
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.
|
4
|
+
version: 0.9.8
|
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-12-
|
12
|
+
date: 2018-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|