json-tools 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. data/lib/jsontools/jsontools.rb +12 -15
  2. metadata +2 -2
@@ -180,12 +180,15 @@ module JsonTools
180
180
 
181
181
  def add params, target
182
182
  ptr = Pointer.new params['path']
183
- fail if ptr.exists? target
184
183
  obj = ptr[target]
185
184
  fail if not (Array === obj || Hash === obj)
186
- obj.insert JsonTools.fix_key(obj,ptr.last),params['value']
185
+ if (Array === obj && ptr.last == '-')
186
+ obj.insert -1,params['value']
187
+ else
188
+ obj.insert JsonTools.fix_key(obj,ptr.last),params['value']
189
+ end
187
190
  rescue
188
- raise FailedOperationError
191
+ raise FailedOperationError
189
192
  end
190
193
 
191
194
  def remove params, target
@@ -206,9 +209,9 @@ module JsonTools
206
209
  end
207
210
 
208
211
  def move_or_copy params, target, move=false
209
- from = Pointer.new params['path']
210
- to = Pointer.new params['to']
211
- fail if !from.exists?(target) || to.exists?(target)
212
+ from = Pointer.new params['from']
213
+ to = Pointer.new params['path']
214
+ fail if !from.exists?(target) #|| to.exists?(target)
212
215
  obj = from[target]
213
216
  val = obj[JsonTools.fix_key(obj,from.last)]
214
217
  remove(({'path'=>params['path']}), target) if move # we only remove it if we're doing a move operation
@@ -255,9 +258,7 @@ module JsonTools
255
258
  def self.string_check params, target, &block
256
259
  ptr = Pointer.new params['path']
257
260
  return false if !ptr.exists?(target)
258
- parent, key = ptr[target], ptr.last
259
- key = JsonTools.fix_key(parent, key)
260
- val = parent[key]
261
+ val = ptr.value target
261
262
  return false unless String === val
262
263
  ignore_case = params['ignore_case']
263
264
  test_val = params['value']
@@ -271,9 +272,7 @@ module JsonTools
271
272
  def self.number_check params, target, &block
272
273
  ptr = Pointer.new params['path']
273
274
  return false if !ptr.exists?(target)
274
- parent, key = ptr[target], ptr.last
275
- key = JsonTools.fix_key(parent, key)
276
- val = parent[key]
275
+ val = ptr.value target
277
276
  test_val = params['value']
278
277
  return false unless (Numeric === val && Numeric === test_val)
279
278
  yield val, test_val
@@ -295,9 +294,7 @@ module JsonTools
295
294
  def self.matches params, target
296
295
  ptr = Pointer.new params['path']
297
296
  return false if !ptr.exists?(target)
298
- parent, key = ptr[target], ptr.last
299
- key = JsonTools.fix_key(parent, key)
300
- val = parent[key]
297
+ val = ptr.value target
301
298
  return false unless String === val
302
299
  ignore_case = params['ignore_case']
303
300
  test_val = params['value']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A JSON Patch + Pointer + Predicates Implementation
15
15
  email: jasnell@gmail.com