dorian-yaml-compare 0.3.2 → 0.3.4

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
  SHA256:
3
- metadata.gz: bfb6914c636ac9da87f840c4791845f6ac23d483e136f472d08b67e61a284dd7
4
- data.tar.gz: 13f3ada06ad6990193eeddade67eb8573b508de4f07439ff9e0419546c9b7e56
3
+ metadata.gz: 7783a8073332f73595ad5baf3f2f38c2f07ef4689e12ea506e6e59f494b5c349
4
+ data.tar.gz: 258bf64eb3418ef98972dc625c851f4e32ab30f59f01c7e9a3c72a5297f0686d
5
5
  SHA512:
6
- metadata.gz: 4df6fa9e9cfae5482c12e02ce84438984c76da48af6ce6a66f6653528c3237d752943e8d09fdb0712723bffd0371851e7725f8edb2d6c2780f313aa49d2f6478
7
- data.tar.gz: 1d8eb292169bfc5f9627c1ee7f0c3a7552dca3aa0ab6e381cde7a939d2d619e033f8a5f212cc0675ee4637221e8d746b6f1780be1c0a57d97561e2c2b0dea738
6
+ metadata.gz: 65011025d40cf7bec1b3dacdf702bfaa7968ac733a94a6d2ac0f4f6049ac7eda3c0b0a5cb2acbf4e0dcc6202b58c2487687ccd6991ebddfe62be33ca58e964bc
7
+ data.tar.gz: 5fb13e6bda73ede8874805556c866d6b08719387368cfb7b9b8c2da51219e689a85f03d7512f71e8512f7b09d0755db10c48c379287f083866aea36a2db910ef
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 "dorian/yaml/compare"
5
- Dorian::Yaml::Compare.run
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-yaml-compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
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-03-09 00:00:00.000000000 Z
11
+ date: 2024-04-03 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
@@ -21,7 +21,6 @@ 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
@@ -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