yaml_properties 0.0.5 → 0.0.6
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.
- data/lib/yaml_properties/diff.rb +40 -0
- data/lib/yaml_properties/parse.rb +7 -0
- data/lib/yaml_properties/version.rb +1 -1
- data/spec/diff_spec.rb +23 -0
- data/spec/fixtures/file1.yml +3 -0
- data/spec/fixtures/file2.yml +4 -0
- data/spec/fixtures/file3.yml +3 -0
- data/spec/fixtures/file4.yml +3 -0
- data/spec/{test.yml → fixtures/test.yml} +0 -0
- data/spec/yaml_config_spec.rb +1 -1
- metadata +16 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
|
3
|
+
class YamlProperties::Diff
|
4
|
+
def initialize a, b
|
5
|
+
@hash_a, @hash_b = read(a, b)
|
6
|
+
unless same?
|
7
|
+
raise ArgumentError.new(error_message)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def error_message
|
14
|
+
"Following keys are not present in both files '#{key_diff}'"
|
15
|
+
end
|
16
|
+
|
17
|
+
def key_diff
|
18
|
+
(keys_a - keys_b) + (keys_b - keys_a)
|
19
|
+
end
|
20
|
+
|
21
|
+
def keys_a
|
22
|
+
@hash_a.keys
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys_b
|
26
|
+
@hash_b.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def same?
|
30
|
+
key_diff.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def read *files
|
34
|
+
files.map do |f|
|
35
|
+
YAML.load File.read(f)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/spec/diff_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../lib/yaml_properties/diff.rb', __FILE__)
|
2
|
+
|
3
|
+
describe YamlProperties::Diff do
|
4
|
+
def f file
|
5
|
+
File.expand_path("../fixtures/#{file}.yml", __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "raises an exception if two YAML files have different keys" do
|
9
|
+
-> {YamlProperties::Diff.new f('file1'), f('file2')}.should raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it "doesn't raise an exception if two YAML files have same keys" do
|
13
|
+
-> {YamlProperties::Diff.new f('file1'), f('file4') }.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises a argument error if two YAML files have present vs. non-present keys" do
|
17
|
+
argument_error = "Following keys are not present in both files '[\"d\"]'"
|
18
|
+
|
19
|
+
-> {YamlProperties::Diff.new f('file2'),f('file3')}.should(
|
20
|
+
raise_error(ArgumentError, argument_error))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
File without changes
|
data/spec/yaml_config_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -74,9 +74,16 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- config/properties.yml
|
76
76
|
- lib/yaml_properties.rb
|
77
|
+
- lib/yaml_properties/diff.rb
|
78
|
+
- lib/yaml_properties/parse.rb
|
77
79
|
- lib/yaml_properties/version.rb
|
80
|
+
- spec/diff_spec.rb
|
81
|
+
- spec/fixtures/file1.yml
|
82
|
+
- spec/fixtures/file2.yml
|
83
|
+
- spec/fixtures/file3.yml
|
84
|
+
- spec/fixtures/file4.yml
|
85
|
+
- spec/fixtures/test.yml
|
78
86
|
- spec/spec_helper.rb
|
79
|
-
- spec/test.yml
|
80
87
|
- spec/yaml_config_spec.rb
|
81
88
|
- yaml_properties.gemspec
|
82
89
|
homepage: ''
|
@@ -105,7 +112,11 @@ specification_version: 3
|
|
105
112
|
summary: ! 'Example: YamlProperties.life_the_universe_and_everything #=> 42 In config/properties.yml
|
106
113
|
life_the_universe_and_everything: 42'
|
107
114
|
test_files:
|
115
|
+
- spec/diff_spec.rb
|
116
|
+
- spec/fixtures/file1.yml
|
117
|
+
- spec/fixtures/file2.yml
|
118
|
+
- spec/fixtures/file3.yml
|
119
|
+
- spec/fixtures/file4.yml
|
120
|
+
- spec/fixtures/test.yml
|
108
121
|
- spec/spec_helper.rb
|
109
|
-
- spec/test.yml
|
110
122
|
- spec/yaml_config_spec.rb
|
111
|
-
has_rdoc:
|