jsonpath 0.9.3 → 0.9.4
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 +5 -5
- data/lib/jsonpath.rb +1 -1
- data/lib/jsonpath/enumerable.rb +2 -2
- data/lib/jsonpath/proxy.rb +10 -0
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +83 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2473ca28bed27ee404a8ad46a73e4752f848f29
|
4
|
+
data.tar.gz: 647e15073ba118cd82ebae0d21a4d7fb056600f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce6cde76b1d9ccb25bbd83d08d28ff8be128555cde22c1cb64a36d5f296d3dd9b6196ea0fd359f7f6ca94b11ddde46728291752c6a733123677dae128fdd694e
|
7
|
+
data.tar.gz: 88052cdd548064d68e4cc6a384214dc1712b8661ae509782b2f38b9cbda61b37753938db50b055022629d77821a0669f5e39759138409da61c544fb365be22b2
|
data/lib/jsonpath.rb
CHANGED
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -77,8 +77,6 @@ class JsonPath
|
|
77
77
|
when Array
|
78
78
|
node.size.times do |index|
|
79
79
|
@_current_node = node[index]
|
80
|
-
# exps = sub_path[1, sub_path.size - 1]
|
81
|
-
# if @_current_node.send("[#{exps.gsub(/@/, '@_current_node')}]")
|
82
80
|
if process_function_or_literal(sub_path[1, sub_path.size - 1])
|
83
81
|
each(@_current_node, nil, pos + 1, &blk)
|
84
82
|
end
|
@@ -104,6 +102,8 @@ class JsonPath
|
|
104
102
|
when :delete
|
105
103
|
if key
|
106
104
|
key.is_a?(Integer) ? context.delete_at(key) : context.delete(key)
|
105
|
+
else
|
106
|
+
context.replace({})
|
107
107
|
end
|
108
108
|
when :substitute
|
109
109
|
if key
|
data/lib/jsonpath/proxy.rb
CHANGED
@@ -46,9 +46,19 @@ class JsonPath
|
|
46
46
|
|
47
47
|
def _delete(obj, path)
|
48
48
|
JsonPath.new(path)[obj, :delete].each
|
49
|
+
obj = _remove(obj)
|
49
50
|
Proxy.new(obj)
|
50
51
|
end
|
51
52
|
|
53
|
+
def _remove(obj)
|
54
|
+
obj.each do |o|
|
55
|
+
if o.is_a?(Hash) || o.is_a?(Array)
|
56
|
+
_remove(o)
|
57
|
+
o.delete({})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
def _compact(obj, path)
|
53
63
|
JsonPath.new(path)[obj, :compact].each
|
54
64
|
Proxy.new(obj)
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -173,6 +173,89 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
173
173
|
assert_equal({ 'you' => nil }, h)
|
174
174
|
end
|
175
175
|
|
176
|
+
def test_delete_2
|
177
|
+
json = { 'store' => {
|
178
|
+
'book' => [
|
179
|
+
{ 'category' => 'reference',
|
180
|
+
'author' => 'Nigel Rees',
|
181
|
+
'title' => 'Sayings of the Century',
|
182
|
+
'price' => 9,
|
183
|
+
'tags' => %w[asdf asdf2] },
|
184
|
+
{ 'category' => 'fiction',
|
185
|
+
'author' => 'Evelyn Waugh',
|
186
|
+
'title' => 'Sword of Honour',
|
187
|
+
'price' => 13 },
|
188
|
+
{ 'category' => 'fiction',
|
189
|
+
'author' => 'Aasdf',
|
190
|
+
'title' => 'Aaasdf2',
|
191
|
+
'price' => 1 }
|
192
|
+
]
|
193
|
+
} }
|
194
|
+
json_deleted = { 'store' => {
|
195
|
+
'book' => [
|
196
|
+
{ 'category' => 'fiction',
|
197
|
+
'author' => 'Evelyn Waugh',
|
198
|
+
'title' => 'Sword of Honour',
|
199
|
+
'price' => 13 },
|
200
|
+
{ 'category' => 'fiction',
|
201
|
+
'author' => 'Aasdf',
|
202
|
+
'title' => 'Aaasdf2',
|
203
|
+
'price' => 1 }
|
204
|
+
]
|
205
|
+
} }
|
206
|
+
assert_equal(json_deleted, JsonPath.for(json).delete("$..store.book[?(@.category == 'reference')]").obj)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_delete_3
|
210
|
+
json = { 'store' => {
|
211
|
+
'book' => [
|
212
|
+
{ 'category' => 'reference',
|
213
|
+
'author' => 'Nigel Rees',
|
214
|
+
'title' => 'Sayings of the Century',
|
215
|
+
'price' => 9,
|
216
|
+
'tags' => %w[asdf asdf2],
|
217
|
+
'this' => {
|
218
|
+
'delete_me' => [
|
219
|
+
'no' => 'do not'
|
220
|
+
]
|
221
|
+
}
|
222
|
+
},
|
223
|
+
{ 'category' => 'fiction',
|
224
|
+
'author' => 'Evelyn Waugh',
|
225
|
+
'title' => 'Sword of Honour',
|
226
|
+
'price' => 13
|
227
|
+
},
|
228
|
+
{ 'category' => 'fiction',
|
229
|
+
'author' => 'Aasdf',
|
230
|
+
'title' => 'Aaasdf2',
|
231
|
+
'price' => 1
|
232
|
+
}
|
233
|
+
]
|
234
|
+
} }
|
235
|
+
json_deleted = { 'store' => {
|
236
|
+
'book' => [
|
237
|
+
{ 'category' => 'reference',
|
238
|
+
'author' => 'Nigel Rees',
|
239
|
+
'title' => 'Sayings of the Century',
|
240
|
+
'price' => 9,
|
241
|
+
'tags' => %w[asdf asdf2],
|
242
|
+
'this' => {}
|
243
|
+
},
|
244
|
+
{ 'category' => 'fiction',
|
245
|
+
'author' => 'Evelyn Waugh',
|
246
|
+
'title' => 'Sword of Honour',
|
247
|
+
'price' => 13
|
248
|
+
},
|
249
|
+
{ 'category' => 'fiction',
|
250
|
+
'author' => 'Aasdf',
|
251
|
+
'title' => 'Aaasdf2',
|
252
|
+
'price' => 1
|
253
|
+
}
|
254
|
+
]
|
255
|
+
} }
|
256
|
+
assert_equal(json_deleted, JsonPath.for(json).delete('$..store.book..delete_me').obj)
|
257
|
+
end
|
258
|
+
|
176
259
|
def test_delete_for_array
|
177
260
|
before = JsonPath.on(@object, '$..store.book[1]')
|
178
261
|
JsonPath.for(@object).delete!('$..store.book[0]')
|
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.4
|
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
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project: jsonpath
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.6.13
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Ruby implementation of http://goessner.net/articles/JsonPath/
|