jsonpath 0.8.5 → 0.8.6

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: 21fea8b1a9938a71633574563954589ec16dcdf0
4
- data.tar.gz: 62627c4ceb79e873a9bcc7a98882bd6637648844
3
+ metadata.gz: dbcb83c2762c708aa6f7ed1bff44def4ef4a6b46
4
+ data.tar.gz: ec7e54dd7bde48f57797666fa764d41573a8b6b5
5
5
  SHA512:
6
- metadata.gz: 93c07f6532086fd40fe7f1df0d9d829256644b1ce070aa3924333f379df383bf824ba82b91479eb7c94e12e9ecbdd87498bc793dc7681ba8601dc33f8069b13a
7
- data.tar.gz: 7d43c2ecac3f114872c37ec21b383b1974b81f3350ac29298dd0f7bd377ffef3890ac7a4f7b5ba25cbd1d1f9498745aa3de119f789b49803eb1c47e96558d864
6
+ metadata.gz: 7a83ff1f0c946ae83ee34a1c9852cc6c05651b70c06c211ae34285a82615ddab21195a62db8a30d747b3ac61b0624f7817556a557d39f39865871e3e69da0308
7
+ data.tar.gz: 60e9ffe8463f7a14ed64f741643b9f60444e6c88a8056862f5beb2a7d65539a063a3f8af2724782d74ce99f3b195f64bafaad91f78536b572470eeb02e776f8b
@@ -84,13 +84,18 @@ class JsonPath
84
84
  end
85
85
 
86
86
  def yield_value(blk, context, key)
87
+ key = Integer(key) rescue key if key
87
88
  case @mode
88
89
  when nil
89
90
  blk.call(key ? context[key] : context)
90
91
  when :compact
91
- context.delete(key) if key && context[key].nil?
92
+ if key && context[key].nil?
93
+ key.is_a?(Integer) ? context.delete_at(key) : context.delete(key)
94
+ end
92
95
  when :delete
93
- context.delete(key) if key
96
+ if key
97
+ key.is_a?(Integer) ? context.delete_at(key) : context.delete(key)
98
+ end
94
99
  when :substitute
95
100
  if key
96
101
  context[key] = blk.call(context[key])
@@ -1,3 +1,3 @@
1
1
  class JsonPath
2
- VERSION = '0.8.5'.freeze
2
+ VERSION = '0.8.6'.freeze
3
3
  end
@@ -170,6 +170,13 @@ class TestJsonpath < MiniTest::Unit::TestCase
170
170
  assert_equal({ 'you' => nil }, h)
171
171
  end
172
172
 
173
+ def test_delete_for_array
174
+ before = JsonPath.on(@object, '$..store.book[1]')
175
+ JsonPath.for(@object).delete!('$..store.book[0]')
176
+ after = JsonPath.on(@object, '$..store.book[0]')
177
+ assert_equal(after, before, 'Before is the second element. After should have been equal to the next element after delete.')
178
+ end
179
+
173
180
  def test_at_sign_in_json_element
174
181
  data =
175
182
  { '@colors' =>
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.8.5
4
+ version: 0.8.6
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: 2017-06-14 00:00:00.000000000 Z
12
+ date: 2017-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json