dorian-yaml-compare 0.3.2 → 0.3.3

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: 0a61a09c5ae8574d6ff57f6355e6d05618a2018c061874d860902ea419707cb4
4
+ data.tar.gz: a0cd44f5ef8521d815319e6ffc27689e82403c1b81627002f90f57b04a5fa466
5
5
  SHA512:
6
- metadata.gz: 4df6fa9e9cfae5482c12e02ce84438984c76da48af6ce6a66f6653528c3237d752943e8d09fdb0712723bffd0371851e7725f8edb2d6c2780f313aa49d2f6478
7
- data.tar.gz: 1d8eb292169bfc5f9627c1ee7f0c3a7552dca3aa0ab6e381cde7a939d2d619e033f8a5f212cc0675ee4637221e8d746b6f1780be1c0a57d97561e2c2b0dea738
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 "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,7 +1,7 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -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