dorian-json-compare 0.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/json-compare +49 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b4d2a4b90e35ee8b70381dbb27d81287e9b41c68ca7054e29b2af1e65cc5c4a
|
4
|
+
data.tar.gz: '0676838b02cbad975fd245b04d60a6b7fa1cc8af7822c3fe3758df649485e75b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e8e858ecdb9a21a172bd95cd868d14c6e875fc0c9aae52360e99ecaea88590df9c23fd524c12da18a4f3e703b94c5a8797860d8717acb07e5eb1b3912565967
|
7
|
+
data.tar.gz: 31a5d8957728ec6bb76237704b95237112cefcd59e3eac396c22635272a033692d13d932fe83871a29ec6c41af128938ab631207c3e300d5dbb8b0ad8f6e82cb
|
data/bin/json-compare
CHANGED
@@ -1,12 +1,55 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require "json"
|
5
|
+
require "dorian/arguments"
|
6
|
+
require "stringio"
|
7
|
+
|
8
|
+
def compare(hash1, hash2, current: "")
|
9
|
+
if hash1.is_a?(Array)
|
10
|
+
hash1.each.with_index { |_, i| compare(hash1[i], hash2[i], current:) }
|
11
|
+
elsif hash1.is_a?(String) || hash2.is_a?(String)
|
12
|
+
if !hash1.is_a?(String)
|
13
|
+
puts "key \"#{current}\" is a string in #{ARGV[1]}"
|
14
|
+
elsif !hash2.is_a?(String)
|
15
|
+
puts "key \"#{current}\" is a string in #{ARGV[0]}"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
(hash1.keys + hash2.keys).uniq.each do |key|
|
19
|
+
full_key = [current, key].reject(&:empty?).join(".")
|
20
|
+
if !hash1.key?(key)
|
21
|
+
puts "missing key \"#{full_key}\" from #{ARGV[0]}"
|
22
|
+
elsif !hash2.key?(key)
|
23
|
+
puts "missing key \"#{full_key}\" from #{ARGV[1]}"
|
24
|
+
else
|
25
|
+
compare(hash1[key], hash2[key], current: full_key)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_captured_stdout
|
32
|
+
original_stdout = $stdout
|
33
|
+
$stdout = StringIO.new
|
34
|
+
yield
|
35
|
+
$stdout.string
|
36
|
+
ensure
|
37
|
+
$stdout = original_stdout
|
7
38
|
end
|
8
39
|
|
9
|
-
|
10
|
-
|
11
|
-
|
40
|
+
parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
|
41
|
+
|
42
|
+
abort parsed.help if parsed.options.help
|
43
|
+
|
44
|
+
if parsed.options.version
|
45
|
+
abort File.read(File.expand_path("../VERSION", __dir__))
|
12
46
|
end
|
47
|
+
|
48
|
+
file1, file2 = parsed.files.map { |file| JSON.parse(File.read(file)) }
|
49
|
+
root1, root2 = parsed.arguments
|
50
|
+
file1 = file1[root1] if root1
|
51
|
+
file2 = file2[root2] if root2
|
52
|
+
|
53
|
+
output = with_captured_stdout { compare(file1, file2) }
|
54
|
+
|
55
|
+
abort output unless output.empty?
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-json-compare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dorian-arguments
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -57,9 +57,9 @@ require_paths:
|
|
57
57
|
- lib
|
58
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '='
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 3.3.4
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|