jsonpath 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonpath.rb +2 -2
- data/lib/jsonpath/enumerable.rb +2 -1
- data/lib/jsonpath/parser.rb +11 -4
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb42f9de5ec60194b2b37e99c6f1b511850d745
|
4
|
+
data.tar.gz: 3a0191bf685d79146dc6ea6e7f89e4a30ec34ab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856c7017b0b064a4cc658f38becbcd3caa0bc50627a063cc46b0b5a002675ddca8a95fef1b42b91df0b63a3f6faf8aaed9f402f646c77da743550c63168ec21b
|
7
|
+
data.tar.gz: b660c60b66d4785f038629c2e47cad03d7e700a81d8b43c17cbdca0a75ce0908c55f8ac5b41f2aa6ec0cf62dc4edac9e2e2199151156b88d207aae8fd7744182
|
data/lib/jsonpath.rb
CHANGED
@@ -12,7 +12,7 @@ class JsonPath
|
|
12
12
|
|
13
13
|
attr_accessor :path
|
14
14
|
|
15
|
-
def initialize(path, opts =
|
15
|
+
def initialize(path, opts = {})
|
16
16
|
@opts = opts
|
17
17
|
scanner = StringScanner.new(path.strip)
|
18
18
|
@path = []
|
@@ -75,7 +75,7 @@ class JsonPath
|
|
75
75
|
end
|
76
76
|
alias_method :[], :enum_on
|
77
77
|
|
78
|
-
def self.on(obj_or_str, path, opts =
|
78
|
+
def self.on(obj_or_str, path, opts = {})
|
79
79
|
new(path, opts).on(process_object(obj_or_str))
|
80
80
|
end
|
81
81
|
|
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -2,7 +2,7 @@ class JsonPath
|
|
2
2
|
class Enumerable
|
3
3
|
include ::Enumerable
|
4
4
|
|
5
|
-
def initialize(path, object, mode, options =
|
5
|
+
def initialize(path, object, mode, options = {})
|
6
6
|
@path = path.path
|
7
7
|
@object = object
|
8
8
|
@mode = mode
|
@@ -38,6 +38,7 @@ class JsonPath
|
|
38
38
|
when '\'', '"'
|
39
39
|
if node.is_a?(Hash)
|
40
40
|
k = sub_path[1, sub_path.size - 2]
|
41
|
+
node[k] ||= nil if @options[:default_path_leaf_to_null]
|
41
42
|
each(node, k, pos + 1, &blk) if node.key?(k)
|
42
43
|
end
|
43
44
|
when '?'
|
data/lib/jsonpath/parser.rb
CHANGED
@@ -38,9 +38,16 @@ class JsonPath
|
|
38
38
|
elsif t = scanner.scan(/(\s+)?[<>=][=~]?(\s+)?/)
|
39
39
|
operator = t
|
40
40
|
elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/)
|
41
|
-
|
41
|
+
# 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
|
42
50
|
elsif t = scanner.scan(/\/\w+\//)
|
43
|
-
|
44
51
|
elsif t = scanner.scan(/.*/)
|
45
52
|
raise "Could not process symbol: #{t}"
|
46
53
|
end
|
@@ -56,8 +63,8 @@ class JsonPath
|
|
56
63
|
|
57
64
|
el = Float(el) rescue el
|
58
65
|
operand = Float(operand) rescue operand
|
59
|
-
|
60
|
-
el.
|
66
|
+
|
67
|
+
el.__send__(operator.strip, operand)
|
61
68
|
end
|
62
69
|
|
63
70
|
private
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -537,12 +537,20 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
537
537
|
initial: true,
|
538
538
|
not: true
|
539
539
|
}.to_json
|
540
|
-
assert_equal [true], JsonPath.on(json, "$.
|
540
|
+
assert_equal [{"initial"=>true, "not"=>true}], JsonPath.on(json, "$.[?(@.initial == true)]")
|
541
541
|
json = {
|
542
542
|
initial: false,
|
543
543
|
not: true
|
544
544
|
}.to_json
|
545
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)]")
|
548
|
+
json = {
|
549
|
+
initial: 'false',
|
550
|
+
not: true
|
551
|
+
}.to_json
|
552
|
+
assert_equal [{"initial"=>"false", "not"=>true}], JsonPath.on(json, "$.[?(@.initial == 'false')]")
|
553
|
+
assert_equal [], JsonPath.on(json, "$.[?(@.initial == false)]")
|
546
554
|
end
|
547
555
|
|
548
556
|
def test_hanging
|
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.2
|
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-
|
12
|
+
date: 2018-06-14 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.
|
160
|
+
rubygems_version: 2.6.12
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: Ruby implementation of http://goessner.net/articles/JsonPath/
|