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.
@@ -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
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require File.expand_path('../diff.rb', __FILE__)
4
+
5
+ raise "Please provide 2 YAML files" unless args.size == 2
6
+
7
+ YamlProperties::Diff.new args[0], args[1]
@@ -1,3 +1,3 @@
1
1
  module YamlProperties
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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
+
@@ -0,0 +1,3 @@
1
+ a: 1
2
+ b: 2
3
+ c: 3
@@ -0,0 +1,4 @@
1
+ a: 1
2
+ b: 2
3
+ c: 3
4
+ d: 4
@@ -0,0 +1,3 @@
1
+ a: 1
2
+ b: 2
3
+ c: 3
@@ -0,0 +1,3 @@
1
+ a: 1
2
+ b: 2
3
+ c: 3
File without changes
@@ -54,7 +54,7 @@ describe YamlProperties do
54
54
  extend YamlProperties
55
55
 
56
56
  def self.yaml_file
57
- "./spec/test.yml"
57
+ "./spec/fixtures/test.yml"
58
58
  end
59
59
  end
60
60
 
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.5
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-15 00:00:00.000000000 Z
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: