json-diff 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beecb0033db3c1e9c3c90d8c008cf3ed0a5b3343
4
- data.tar.gz: 240ccbca2632cf8ec4bdd01116b3199fe94214b5
3
+ metadata.gz: a5617c912b4ef9b118b051573cde8543ea6901cb
4
+ data.tar.gz: 1e96e1c3461d13e414d9190b7d802f315bd2ceb5
5
5
  SHA512:
6
- metadata.gz: 5b94f9b1e432b7f8a7ad6302fad09b7de74ed42c227337ab08831068d37e2c2cdee671fd77d8785efd4d23e72ce17b80192bdab9ed3d09f8bf640fb520a161f3
7
- data.tar.gz: 6e6e3ea10644f747d3c5a896bea90867138d187a230205c358ac043765870cc0e1603da1cc1e515ae2c24008b85946b8a8768a7c51620aa3935a899105e6253d
6
+ metadata.gz: 01a46567018acb47c04c3263625f20d35d4239f4f9ebf8d5d7816d5b9192e9c0de09ccb0092c2ad9ff6fec008ed429002945ef024bb0d388b088f2793183d6b3
7
+ data.tar.gz: dbb9d3b621e1c773de510e365191314ddc88d00333888a90cd723b1330370946787204a1fa8338fde85816122490d3dbd8024b8dad84fec500b5296a7a98ca18
data/README.md CHANGED
@@ -21,12 +21,19 @@ Outputs [RFC6902][]. Look at [hana][] for a JSON patch algorithm that can use th
21
21
 
22
22
  - `include_was`: include a `was` field in remove and replace operations, to show the old value. Allows computing reverse operations without the source JSON.
23
23
  - `moves`\*: include move operations. Set it to false to remove clutter.
24
- - `additions`\*: include add operations. Se it to false to remove clutter.
24
+ - `additions`\*: include add operations. Set it to false to remove clutter.
25
25
  - `original_indices`\*: array indices are those from the source array (for `from` fields, or `path` fields on remove operations) or the target array (for other `path` fields). It eases manual checking of differences.
26
26
  - `similarity`: procedure taking (before, after) objects. Returns a probability between 0 and 1 of how likely `after` is a modification of `before`, or nil if you wish to fall back to the default computation.
27
27
 
28
28
  \* Changing this option prevents the use of the output for JSON patching.
29
29
 
30
+ You can also install its associated program to use this on the command line:
31
+
32
+ ```bash
33
+ gem install json-diff # On Linux, you may need to use sudo
34
+ json-diff before.json after.json
35
+ ```
36
+
30
37
  # Heart
31
38
 
32
39
  - Recursive similarity computation between any two Ruby values.
@@ -262,7 +262,7 @@ module JsonDiff
262
262
  # And map indices from after to before additions
263
263
  # (removals, since it is reversed).
264
264
  addition_map = IndexMaps.new
265
- pairing[:added].each { |ad| addition_map.removal(ad) }
265
+ pairing[:added].reverse.each { |ad| addition_map.removal(ad) }
266
266
 
267
267
  moves = {}
268
268
  orig_before = {}
@@ -25,7 +25,9 @@ module JsonDiff
25
25
  def initialize(pivot)
26
26
  @pivot = pivot
27
27
  end
28
+ end
28
29
 
30
+ class AdditionIndexMap < IndexMap
29
31
  def map(index)
30
32
  if index >= @pivot
31
33
  index + 1
@@ -35,9 +37,6 @@ module JsonDiff
35
37
  end
36
38
  end
37
39
 
38
- class AdditionIndexMap < IndexMap
39
- end
40
-
41
40
  class RemovalIndexMap < IndexMap
42
41
  def map(index)
43
42
  if index >= @pivot
@@ -1,3 +1,3 @@
1
1
  module JsonDiff
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -71,6 +71,15 @@ describe JsonDiff do
71
71
  ])
72
72
  end
73
73
 
74
+ it "should be able to diff an array with many additions at its start" do
75
+ diff = JsonDiff.diff([0], [1, 2, 3, 0])
76
+ expect(diff).to eql([
77
+ {'op' => 'add', 'path' => "/0", 'value' => 1},
78
+ {'op' => 'add', 'path' => "/1", 'value' => 2},
79
+ {'op' => 'add', 'path' => "/2", 'value' => 3},
80
+ ])
81
+ end
82
+
74
83
  it "should be able to diff two arrays with mixed content" do
75
84
  diff = JsonDiff.diff(["laundry", 12, {'pillar' => 0}, true], [true, {'pillar' => 1}, 3, 12], include_was: true)
76
85
  expect(diff).to eql([
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.4.0
4
+ version: 0.4.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: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2017-05-04 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