yamldiff 0.0.8 → 0.0.9
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 +7 -0
- data/.gitignore +1 -0
- data/README.md +1 -0
- data/bin/yamldiff +12 -0
- data/lib/yamldiff.rb +1 -0
- data/lib/yamldiff/version.rb +1 -1
- data/lib/yamldiff/yamldiff.rb +5 -5
- data/lib/yamldiff/yamldiff_error.rb +28 -3
- data/spec/lib/yamldiff_error_spec.rb +31 -0
- data/spec/lib/yamldiff_spec.rb +16 -0
- data/yamldiff.gemspec +1 -0
- metadata +49 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27d91d4a12050a4e55e9ad4ea4da5c11dfb03822
|
4
|
+
data.tar.gz: 36e04acd943bb9203850964de70d3ce89c2bd6b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78d02396e4d39a5392b94ea79314c83f8a3f8a99e3c595234a808154b3e404e6a9f90a7b038f1f711c72aef5aba93ee9a97b3cf6fa3e71cf4de513b60be1eda7
|
7
|
+
data.tar.gz: eee3454912b71aed4e277e9fc18b346a787da143f670c3f5ea23635feb38896103fa2a938b1a2cd1b8c3afc784e33814deab23f15a03ad9b5a4413c2a3c58421
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/bin/yamldiff
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
4
|
+
require 'yamldiff'
|
5
|
+
|
6
|
+
if ARGV.size != 2
|
7
|
+
$stderr.puts "USAGE: yamldiff file1 file2"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
errors = Yamldiff.diff_yaml(ARGV[0], ARGV[1])
|
12
|
+
puts errors[ARGV[1]]
|
data/lib/yamldiff.rb
CHANGED
data/lib/yamldiff/version.rb
CHANGED
data/lib/yamldiff/yamldiff.rb
CHANGED
@@ -2,8 +2,8 @@ class Yamldiff
|
|
2
2
|
class << self
|
3
3
|
# Compare the two yaml files
|
4
4
|
def diff_yaml(first, second, errors_for = {})
|
5
|
-
primary = YAML.load(File.
|
6
|
-
secondary = YAML.load(File.
|
5
|
+
primary = YAML.load(ERB.new(File.read(first)).result)
|
6
|
+
secondary = YAML.load(ERB.new(File.read(second)).result)
|
7
7
|
errors_for[second] = compare_hashes(primary, secondary)
|
8
8
|
errors_for
|
9
9
|
end
|
@@ -20,13 +20,13 @@ class Yamldiff
|
|
20
20
|
|
21
21
|
first.each do |key, value|
|
22
22
|
unless second.key?(key)
|
23
|
-
errors << YamldiffKeyError.new(key, context)
|
23
|
+
errors << YamldiffKeyError.new(key, context)
|
24
24
|
next
|
25
25
|
end
|
26
26
|
|
27
27
|
value2 = second[key]
|
28
28
|
if (value.class != value2.class)
|
29
|
-
errors << YamldiffKeyValueTypeError.new(key, context)
|
29
|
+
errors << YamldiffKeyValueTypeError.new(key, context)
|
30
30
|
next
|
31
31
|
end
|
32
32
|
|
@@ -36,7 +36,7 @@ class Yamldiff
|
|
36
36
|
end
|
37
37
|
|
38
38
|
if (value != value2)
|
39
|
-
errors << YamldiffKeyValueError.new(key, context
|
39
|
+
errors << YamldiffKeyValueError.new(key, context, Diffy::Diff.new(value.to_s + "\n", value2.to_s + "\n"))
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -6,6 +6,31 @@ class YamldiffError
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
class YamldiffKeyError < YamldiffError
|
10
|
-
|
11
|
-
|
9
|
+
class YamldiffKeyError < YamldiffError
|
10
|
+
def to_s
|
11
|
+
"Missing key: #{@context.join(".")}.#{@key}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class YamldiffKeyValueTypeError < YamldiffError
|
16
|
+
def to_s
|
17
|
+
"Key value type mismatch: #{@context.join(".")}.#{@key}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class YamldiffKeyValueError < YamldiffError
|
22
|
+
def initialize(key, context, diff = nil)
|
23
|
+
super key, context
|
24
|
+
@diff = diff
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
output = []
|
29
|
+
output << "Key content differs: #{@context.join(".")}.#{@key}"
|
30
|
+
if @diff
|
31
|
+
output << "Diff:"
|
32
|
+
output << @diff
|
33
|
+
end
|
34
|
+
output.join("\n")
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe YamldiffKeyError, "#to_s" do
|
4
|
+
it "outputs human readable text" do
|
5
|
+
YamldiffKeyError.new('key', ['root', 'namespace']).to_s.should == "Missing key: root.namespace.key"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe YamldiffKeyValueTypeError, "#to_s" do
|
10
|
+
it "outputs human readable text" do
|
11
|
+
YamldiffKeyValueTypeError.new('key', ['root', 'namespace']).to_s.should == "Key value type mismatch: root.namespace.key"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe YamldiffKeyValueError, "#to_s" do
|
16
|
+
it "outputs human readable text" do
|
17
|
+
YamldiffKeyValueError.new('key', ['root', 'namespace']).to_s.should == "Key content differs: root.namespace.key"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "outputs diff if given" do
|
21
|
+
str1 = "foo\n"
|
22
|
+
str2 = "bar\n"
|
23
|
+
diff = Diffy::Diff.new(str1, str2)
|
24
|
+
YamldiffKeyValueError.new('key', ['root', 'namespace'], diff).to_s.should == <<-OUTPUT
|
25
|
+
Key content differs: root.namespace.key
|
26
|
+
Diff:
|
27
|
+
-foo
|
28
|
+
+bar
|
29
|
+
OUTPUT
|
30
|
+
end
|
31
|
+
end
|
data/spec/lib/yamldiff_spec.rb
CHANGED
@@ -117,5 +117,21 @@ describe Yamldiff do
|
|
117
117
|
result[second].first.key.should eql("bar")
|
118
118
|
result[second].first.context.should eql(["en", "baz"])
|
119
119
|
end
|
120
|
+
|
121
|
+
it "diffs the output when the values are different and passes diff to error" do
|
122
|
+
first = "./en.yml"
|
123
|
+
second = "./es.yml"
|
124
|
+
File.open(first, "w") do |f|
|
125
|
+
f.puts("en: ")
|
126
|
+
f.puts(" app_name: 'Verbosefish'")
|
127
|
+
end
|
128
|
+
File.open(second, "w") do |f|
|
129
|
+
f.puts("en: ")
|
130
|
+
f.puts(" app_name: 'Verboszefish'")
|
131
|
+
end
|
132
|
+
Diffy::Diff.expects(:new).with("Verbosefish\n", "Verboszefish\n").returns("DIFF")
|
133
|
+
YamldiffKeyValueError.expects(:new).with('app_name', ['en'], 'DIFF')
|
134
|
+
result = subject.diff_yaml(first, second)
|
135
|
+
end
|
120
136
|
end
|
121
137
|
end
|
data/yamldiff.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "yamldiff"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Yamldiff::VERSION
|
17
|
+
gem.add_dependency 'diffy'
|
17
18
|
gem.add_development_dependency 'fakefs'
|
18
19
|
gem.add_development_dependency 'rake'
|
19
20
|
gem.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,93 +1,119 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yamldiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jonathan R. Wallace
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: diffy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: fakefs
|
16
|
-
requirement:
|
17
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - ">="
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: '0'
|
22
34
|
type: :development
|
23
35
|
prerelease: false
|
24
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
25
41
|
- !ruby/object:Gem::Dependency
|
26
42
|
name: rake
|
27
|
-
requirement:
|
28
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
29
44
|
requirements:
|
30
|
-
- -
|
45
|
+
- - ">="
|
31
46
|
- !ruby/object:Gem::Version
|
32
47
|
version: '0'
|
33
48
|
type: :development
|
34
49
|
prerelease: false
|
35
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
36
55
|
- !ruby/object:Gem::Dependency
|
37
56
|
name: rspec
|
38
|
-
requirement:
|
39
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
40
58
|
requirements:
|
41
|
-
- -
|
59
|
+
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
43
61
|
version: '0'
|
44
62
|
type: :development
|
45
63
|
prerelease: false
|
46
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
47
69
|
description: Shows the difference yaml keys
|
48
70
|
email:
|
49
71
|
- jonathan.wallace@gmail.com
|
50
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- yamldiff
|
51
74
|
extensions: []
|
52
75
|
extra_rdoc_files: []
|
53
76
|
files:
|
54
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
55
79
|
- Gemfile
|
56
80
|
- LICENSE
|
57
81
|
- README.md
|
58
82
|
- Rakefile
|
83
|
+
- bin/yamldiff
|
59
84
|
- lib/yamldiff.rb
|
60
85
|
- lib/yamldiff/version.rb
|
61
86
|
- lib/yamldiff/yamldiff.rb
|
62
87
|
- lib/yamldiff/yamldiff_error.rb
|
88
|
+
- spec/lib/yamldiff_error_spec.rb
|
63
89
|
- spec/lib/yamldiff_spec.rb
|
64
90
|
- spec/spec_helper.rb
|
65
91
|
- yamldiff.gemspec
|
66
92
|
homepage: ''
|
67
93
|
licenses: []
|
94
|
+
metadata: {}
|
68
95
|
post_install_message:
|
69
96
|
rdoc_options: []
|
70
97
|
require_paths:
|
71
98
|
- lib
|
72
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
100
|
requirements:
|
75
|
-
- -
|
101
|
+
- - ">="
|
76
102
|
- !ruby/object:Gem::Version
|
77
103
|
version: '0'
|
78
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
105
|
requirements:
|
81
|
-
- -
|
106
|
+
- - ">="
|
82
107
|
- !ruby/object:Gem::Version
|
83
108
|
version: '0'
|
84
109
|
requirements: []
|
85
110
|
rubyforge_project:
|
86
|
-
rubygems_version:
|
111
|
+
rubygems_version: 2.2.2
|
87
112
|
signing_key:
|
88
|
-
specification_version:
|
113
|
+
specification_version: 4
|
89
114
|
summary: Yamldiff will tell you when and where you have differences between two yaml
|
90
115
|
files. It prints out a list of missing keys for the second file.
|
91
116
|
test_files:
|
117
|
+
- spec/lib/yamldiff_error_spec.rb
|
92
118
|
- spec/lib/yamldiff_spec.rb
|
93
119
|
- spec/spec_helper.rb
|