254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/json_p3/patch.rb', line 254
def apply(value, index)
_source_parent, source_obj = @from.resolve_with_parent(value)
if source_obj == JSONP3::JSONPointer::UNDEFINED
raise JSONPatchError,
"source object does not exist (#{name}:#{index})"
end
dest_parent, _dest_obj = @pointer.resolve_with_parent(value)
return deep_copy(source_obj) if dest_parent == JSONP3::JSONPointer::UNDEFINED
dest_target = @pointer.tokens.last
if dest_target == JSONP3::JSONPointer::UNDEFINED
raise JSONPatchError,
"unexpected operation (#{name}:#{index})"
end
if dest_parent.is_a?(Array)
if dest_target == "-"
dest_parent << source_obj
else
dest_parent.insert(dest_target.to_i, deep_copy(source_obj))
end
elsif dest_parent.is_a?(Hash)
dest_parent[dest_target] = deep_copy(source_obj)
else
raise JSONPatchError, "unexpected operation on #{dest_parent.class} (#{name}:#{index})"
end
value
end
|