json-diff 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/json-diff/diff.rb +1 -1
- data/lib/json-diff/operation.rb +3 -1
- data/lib/json-diff/version.rb +1 -1
- data/spec/json-diff/diff_spec.rb +9 -0
- data/spec/json-diff/operation_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a49d9630f57ff6fc69869d27d2a6cee854b4b09e
|
4
|
+
data.tar.gz: cb67cc7d6abff730cfd6bb5fe8856196da4c94e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89cd581b2d433f35f38e8d4b03116e0d77d04d5a0b11cd5594492850aed1b24a8bea03440f0e09b83ba9c57c8af31cd013753d46605d13b32d7676b2bd9c40ff
|
7
|
+
data.tar.gz: c997bfdd2fc503857a522949bfd30bfc39a2ac73f0784109ca9035467276e07d734e233095df55ce572046dd52c44b775b2fb522e3a6c52c6baa479cd2c8e462
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ gem install json-diff # Or `gem 'json-diff'` in your Gemfile.
|
|
9
9
|
```ruby
|
10
10
|
require 'json-diff'
|
11
11
|
JsonDiff.diff(1, 2)
|
12
|
-
#> [{:op => :replace, :path => "
|
12
|
+
#> [{:op => :replace, :path => "", :value => 2}]
|
13
13
|
```
|
14
14
|
|
15
15
|
Outputs [RFC6902][]. Look at [hana][] for a JSON patch algorithm that can use this output.
|
data/lib/json-diff/diff.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module JsonDiff
|
2
2
|
|
3
3
|
def self.diff(before, after, opts = {})
|
4
|
-
path = opts[:path] || '
|
4
|
+
path = opts[:path] || ''
|
5
5
|
include_addition = (opts[:additions] == nil) ? true : opts[:additions]
|
6
6
|
include_moves = (opts[:moves] == nil) ? true : opts[:moves]
|
7
7
|
include_was = (opts[:include_was] == nil) ? false : opts[:include_was]
|
data/lib/json-diff/operation.rb
CHANGED
@@ -3,6 +3,8 @@ module JsonDiff
|
|
3
3
|
# Convert a list of strings or numbers to an RFC6901 JSON pointer.
|
4
4
|
# http://tools.ietf.org/html/rfc6901
|
5
5
|
def self.json_pointer(path)
|
6
|
+
return "" if path == []
|
7
|
+
|
6
8
|
escaped_path = path.map do |key|
|
7
9
|
if key.is_a?(String)
|
8
10
|
key.gsub('~', '~0')
|
@@ -17,7 +19,7 @@ module JsonDiff
|
|
17
19
|
|
18
20
|
# Add a key to a JSON pointer.
|
19
21
|
def self.extend_json_pointer(pointer, key)
|
20
|
-
if pointer == '
|
22
|
+
if pointer == ''
|
21
23
|
json_pointer([key])
|
22
24
|
else
|
23
25
|
pointer + json_pointer([key])
|
data/lib/json-diff/version.rb
CHANGED
data/spec/json-diff/diff_spec.rb
CHANGED
@@ -84,6 +84,15 @@ describe JsonDiff do
|
|
84
84
|
])
|
85
85
|
end
|
86
86
|
|
87
|
+
# Trans-type
|
88
|
+
|
89
|
+
it "should be able to diff two objects of mixed type" do
|
90
|
+
diff = JsonDiff.diff(0, "0", include_was: true)
|
91
|
+
expect(diff).to eql([
|
92
|
+
{'op' => 'replace', 'path' => '', 'was' => 0, 'value' => "0"}
|
93
|
+
])
|
94
|
+
end
|
95
|
+
|
87
96
|
# Options
|
88
97
|
|
89
98
|
it "should be able to diff two integer arrays with original indices" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thaddée Tyl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Take two Ruby objects that can be serialized to JSON. Output an array
|
14
14
|
of operations (additions, deletions, moves) that would convert the first one to
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.5.1
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Compute the difference between two JSON-serializable Ruby objects.
|