dorian-yaml-compare 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 209600762585c87f04acd78162361b374f5bceb7d707e21c5914dd12ff955afe
4
+ data.tar.gz: b3a86e92e978644b43c7e3605cd691f61b7375ef0540d5bc88178dac2a749651
5
+ SHA512:
6
+ metadata.gz: a3cc98cb1d6de336a4ecff3717d1c7199da3cbcf79d4ebc163995e8d02941dc6466067479b1b5492c73806b0d3a7e9cca51ea0ddbc1d68aa0c3f6075d8533907
7
+ data.tar.gz: a82c4e747761e8bc2a35c8524f64b21f8164afacf3220ba4a75d161b88407a5aa855ce81a17009173ae0fb8d014b9f9eb8f81c2df88a19e56f9be729224f1a45
data/bin/yaml-compare ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dorian/yaml/compare'
4
+ Dorian::Yaml::Compare.run
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+
3
+ module Dorian
4
+ module Yaml
5
+ class Compare
6
+ def self.run
7
+ if ARGV.size < 2 || ARGV.size > 4
8
+ puts 'USAGE: yaml-compare FILE1 FILE2 [ROOT1] [ROOT2]'
9
+ exit
10
+ end
11
+
12
+ file1 = YAML.safe_load(File.read(ARGV[0]))
13
+ file2 = YAML.safe_load(File.read(ARGV[1]))
14
+ root1 = ARGV[2]
15
+ root2 = ARGV[3]
16
+ file1 = file1[root1] if !root1.nil?
17
+ file2 = file2[root2] if !root2.nil?
18
+
19
+ compare(file1, file2)
20
+ end
21
+
22
+ def self.compare(hash1, hash2, current: '')
23
+ if hash1.kind_of?(Array)
24
+ hash1.each.with_index do |_, i|
25
+ compare(hash1[i], hash2[i], current: current)
26
+ end
27
+ elsif hash1.kind_of?(String) || hash2.kind_of?(String)
28
+ if !hash1.kind_of?(String)
29
+ puts "key \"#{current}\" is a string in #{ARGV[1]}"
30
+ elsif !hash2.kind_of?(String)
31
+ puts "key \"#{current}\" is a string in #{ARGV[0]}"
32
+ end
33
+ else
34
+ (hash1.keys + hash2.keys).uniq.each do |key|
35
+ full_key = [current, key].reject(&:empty?).join(".")
36
+ if !hash1.key?(key)
37
+ puts "missing key \"#{full_key}\" from #{ARGV[0]}"
38
+ elsif !hash2.key?(key)
39
+ puts "missing key \"#{full_key}\" from #{ARGV[1]}"
40
+ else
41
+ compare(hash1[key], hash2[key], current: full_key)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dorian-yaml-compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Compares keys of two YAML files, typically locales files in a Ruby on Rails application
15
+
16
+ e.g. `yaml-compare config/locales/en.yml config/locales/fr.yml en fr`
17
+ email: dorian@dorianmarie.fr
18
+ executables:
19
+ - yaml-compare
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/yaml-compare
24
+ - lib/dorian/yaml/compare.rb
25
+ homepage: https://github.com/dorianmariefr/yaml-compare
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubygems_version: 3.2.22
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Compares keys of two YAML files, typically locales files in a Ruby on Rails
48
+ application
49
+ test_files: []