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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ff98bfabbd5790a20441a9efb6abbc3ff11214a
4
- data.tar.gz: 36be41ebbaee8a09fedf8199a81e236692261d1a
3
+ metadata.gz: a49d9630f57ff6fc69869d27d2a6cee854b4b09e
4
+ data.tar.gz: cb67cc7d6abff730cfd6bb5fe8856196da4c94e2
5
5
  SHA512:
6
- metadata.gz: b140221da9b734eaaf0532e8391b50e0dca60d6ea39c3b4a0b8c0c0952392ac02e5f65864242a5f131934fd75e02a74de16a5f59c8e9182beb14b1c86201d0a7
7
- data.tar.gz: dea0ec9287eb8e4bbe5f8948e3ec9a398408d26b0f1a5f8af9774e14a406686493d60420232412d82c168e5f60c7372eafc2ba89f3a05471ae37a3d7ca643cb7
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 => "/", :value => 2}]
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.
@@ -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]
@@ -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])
@@ -1,3 +1,3 @@
1
1
  module JsonDiff
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -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
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe JsonDiff do
4
4
  it "should convert the root to a JSON pointer" do
5
5
  json_pointer = JsonDiff.json_pointer([])
6
- expect(json_pointer).to eql("/")
6
+ expect(json_pointer).to eql("")
7
7
  end
8
8
 
9
9
  it "should convert a path to a JSON pointer" 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.0
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-07-08 00:00:00.000000000 Z
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.4.5.1
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.