jsonpath 0.9.1 → 0.9.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa8657a28248b15d9ae03ef56bbfa2a436fec517
4
- data.tar.gz: 41e9c32a10b1e26423b7833cb547f2d475798225
3
+ metadata.gz: 6fb42f9de5ec60194b2b37e99c6f1b511850d745
4
+ data.tar.gz: 3a0191bf685d79146dc6ea6e7f89e4a30ec34ab6
5
5
  SHA512:
6
- metadata.gz: b505037a9c8d5d7cf2be89838edb95a7f2ac31f097b8ff81c9c16b7b6205ce49cf19c4e297cb4a83be48b1dbcc026c85ae875c9bd93b7b40a888c09714e58a2b
7
- data.tar.gz: 65a6f59db06dac30434fbf113f12476ef7c944b47589cceee468e4984566ce8157d7730d91e43d1d6d3d639995337eae3065ef715ec2a8e362e260f71c8c5a41
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 = nil)
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 = nil)
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
 
@@ -2,7 +2,7 @@ class JsonPath
2
2
  class Enumerable
3
3
  include ::Enumerable
4
4
 
5
- def initialize(path, object, mode, options = nil)
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 '?'
@@ -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
- operand = operator.strip == "=~" ? t.to_regexp : t.delete("'").strip
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
- operand = false if operand == 'false' && el == false
60
- el.send(operator.strip, operand)
66
+
67
+ el.__send__(operator.strip, operand)
61
68
  end
62
69
 
63
70
  private
@@ -1,3 +1,3 @@
1
1
  class JsonPath
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.2'.freeze
3
3
  end
@@ -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, "$.initial[?(@)]")
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.1
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-08 00:00:00.000000000 Z
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.14
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/