json_diff 0.0.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.
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2016 Chris Roberts <chrisvroberts@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
@@ -0,0 +1,59 @@
1
+ require 'json_diff/version'
2
+
3
+ # Provides helper methods to compare object trees like those generated by JSON.parse
4
+ # and generate a diff list.
5
+ module JSONDiff
6
+ # Assumes a and b are of class Hash.
7
+ def self.objects(a, b, path='')
8
+ differences = []
9
+
10
+ a.each do |k, v|
11
+ if b.has_key? k
12
+ if v.class != b[k].class
13
+ differences << "type mismatch: #{path}/#{k} '#{v.class}' != '#{b[k].class}'"
14
+ else
15
+ if v.is_a? Hash
16
+ differences += objects(v, b[k], "#{path}/#{k}")
17
+ elsif v.is_a? Array
18
+ differences += arrays(v, b[k], "#{path}/#{k}")
19
+ elsif v != b[k] # String, TrueClass, FalseClass, NilClass, Float, Fixnum
20
+ differences << "value mismatch: #{path}/#{k} '#{v}' != '#{b[k]}'"
21
+ end
22
+ end
23
+ else
24
+ differences << "b is missing: #{path}/#{k}"
25
+ end
26
+ end
27
+
28
+ (b.keys - a.keys).each do |k, v|
29
+ differences << "a is missing: #{path}/#{k}"
30
+ end
31
+
32
+ differences
33
+ end
34
+
35
+ # Assumes a and b are of class Array.
36
+ def self.arrays(a, b, path='/')
37
+ differences = []
38
+
39
+ if a.size != b.size
40
+ differences << "size mismatch: #{path}"
41
+ else
42
+ a.zip(b).each_with_index do |pair, index|
43
+ if pair[0].class != pair[1].class
44
+ differences << "type mismatch: #{path}[#{index}] '#{pair[0].class}' != '#{pair[1].class}'"
45
+ else
46
+ if pair[0].is_a? Hash
47
+ differences += objects(pair[0], pair[1], "#{path}[#{index}]")
48
+ elsif pair[0].is_a? Array
49
+ differences += arrays(pair[0], pair[1], "#{path}[#{index}]")
50
+ elsif pair[0] != pair[1] # String, TrueClass, FalseClass, NilClass, Float, Fixnum
51
+ differences << "value mismatch: #{path}[#{index}] '#{pair[0]}' != '#{pair[1]}'"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ differences
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module JSONDiff
2
+ module Version
3
+ STRING = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Roberts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &5093712 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '10.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *5093712
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &5092968 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.4'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *5092968
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &5092524 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.3
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *5092524
50
+ description: A gem to compare JSON object trees
51
+ email:
52
+ - chrisvroberts@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - LICENSE.md
58
+ - lib/json_diff.rb
59
+ - lib/json_diff/version.rb
60
+ homepage: https://github.com/chrisvroberts/json_diff
61
+ licenses:
62
+ - MIT
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.16
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: json_diff-#{JSONDiff::Version::STRING}
85
+ test_files: []