dorian-yaml-compare 0.3.1 → 0.3.3
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 +4 -4
- data/bin/yaml-compare +49 -2
- metadata +3 -4
- data/lib/dorian/yaml/compare.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a61a09c5ae8574d6ff57f6355e6d05618a2018c061874d860902ea419707cb4
|
4
|
+
data.tar.gz: a0cd44f5ef8521d815319e6ffc27689e82403c1b81627002f90f57b04a5fa466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 257acd3703e8b1428b7e284801cfdcf5c9dde36796586bf82cc849f001a254fae985686b7e13051ee0afcc6fa6e2361e1820501a5d910e879fbdb183ecbe224e
|
7
|
+
data.tar.gz: c670e51c2c16c85321f5c4a546a1a69724d90990a67a1512ac8808bdecfae406f59b591973509c2cfca1cf5334c98f2c8de3e22e7fbe312b3e2d102be764a921
|
data/bin/yaml-compare
CHANGED
@@ -1,5 +1,52 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "
|
5
|
-
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
def compare(hash1, hash2, current: "")
|
7
|
+
if hash1.is_a?(Array)
|
8
|
+
hash1.each.with_index { |_, i| compare(hash1[i], hash2[i], current:) }
|
9
|
+
elsif hash1.is_a?(String) || hash2.is_a?(String)
|
10
|
+
if !hash1.is_a?(String)
|
11
|
+
puts "key \"#{current}\" is a string in #{ARGV[1]}"
|
12
|
+
elsif !hash2.is_a?(String)
|
13
|
+
puts "key \"#{current}\" is a string in #{ARGV[0]}"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
(hash1.keys + hash2.keys).uniq.each do |key|
|
17
|
+
full_key = [current, key].reject(&:empty?).join(".")
|
18
|
+
if !hash1.key?(key)
|
19
|
+
puts "missing key \"#{full_key}\" from #{ARGV[0]}"
|
20
|
+
elsif !hash2.key?(key)
|
21
|
+
puts "missing key \"#{full_key}\" from #{ARGV[1]}"
|
22
|
+
else
|
23
|
+
compare(hash1[key], hash2[key], current: full_key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def with_captured_stdout(&block)
|
30
|
+
original_stdout = $stdout
|
31
|
+
$stdout = StringIO.new
|
32
|
+
block.call
|
33
|
+
$stdout.string
|
34
|
+
ensure
|
35
|
+
$stdout = original_stdout
|
36
|
+
end
|
37
|
+
|
38
|
+
if ARGV.size < 2 || ARGV.size > 4
|
39
|
+
puts "USAGE: yaml-compare FILE1 FILE2 [ROOT1] [ROOT2]"
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
file1 = YAML.safe_load_file(ARGV[0])
|
44
|
+
file2 = YAML.safe_load_file(ARGV[1])
|
45
|
+
root1 = ARGV[2]
|
46
|
+
root2 = ARGV[3]
|
47
|
+
file1 = file1[root1] unless root1.nil?
|
48
|
+
file2 = file2[root2] unless root2.nil?
|
49
|
+
|
50
|
+
output = with_captured_stdout { compare(file1, file2) }
|
51
|
+
|
52
|
+
abort output unless output.empty?
|
metadata
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-yaml-compare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
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-
|
11
|
+
date: 2024-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Compares keys of two YAML files, typically locales files in a Ruby on Rails application
|
15
15
|
|
16
16
|
e.g. `yaml-compare config/locales/en.yml config/locales/fr.yml en fr`
|
17
|
-
email: dorian@dorianmarie.
|
17
|
+
email: dorian@dorianmarie.com
|
18
18
|
executables:
|
19
19
|
- yaml-compare
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- bin/yaml-compare
|
24
|
-
- lib/dorian/yaml/compare.rb
|
25
24
|
homepage: https://github.com/dorianmariecom/yaml-compare
|
26
25
|
licenses:
|
27
26
|
- MIT
|
data/lib/dorian/yaml/compare.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module Dorian
|
6
|
-
module Yaml
|
7
|
-
class Compare
|
8
|
-
def self.run
|
9
|
-
if ARGV.size < 2 || ARGV.size > 4
|
10
|
-
puts "USAGE: yaml-compare FILE1 FILE2 [ROOT1] [ROOT2]"
|
11
|
-
exit
|
12
|
-
end
|
13
|
-
|
14
|
-
file1 = YAML.safe_load_file(ARGV[0])
|
15
|
-
file2 = YAML.safe_load_file(ARGV[1])
|
16
|
-
root1 = ARGV[2]
|
17
|
-
root2 = ARGV[3]
|
18
|
-
file1 = file1[root1] unless root1.nil?
|
19
|
-
file2 = file2[root2] unless root2.nil?
|
20
|
-
|
21
|
-
output = with_captured_stdout { compare(file1, file2) }
|
22
|
-
|
23
|
-
abort output unless output.empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.compare(hash1, hash2, current: "")
|
27
|
-
if hash1.is_a?(Array)
|
28
|
-
hash1.each.with_index { |_, i| compare(hash1[i], hash2[i], current:) }
|
29
|
-
elsif hash1.is_a?(String) || hash2.is_a?(String)
|
30
|
-
if !hash1.is_a?(String)
|
31
|
-
puts "key \"#{current}\" is a string in #{ARGV[1]}"
|
32
|
-
elsif !hash2.is_a?(String)
|
33
|
-
puts "key \"#{current}\" is a string in #{ARGV[0]}"
|
34
|
-
end
|
35
|
-
else
|
36
|
-
(hash1.keys + hash2.keys).uniq.each do |key|
|
37
|
-
full_key = [current, key].reject(&:empty?).join(".")
|
38
|
-
if !hash1.key?(key)
|
39
|
-
puts "missing key \"#{full_key}\" from #{ARGV[0]}"
|
40
|
-
elsif !hash2.key?(key)
|
41
|
-
puts "missing key \"#{full_key}\" from #{ARGV[1]}"
|
42
|
-
else
|
43
|
-
compare(hash1[key], hash2[key], current: full_key)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.with_captured_stdout(&block)
|
50
|
-
original_stdout = $stdout
|
51
|
-
$stdout = StringIO.new
|
52
|
-
block.call
|
53
|
-
$stdout.string
|
54
|
-
ensure
|
55
|
-
$stdout = original_stdout
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|