isomer 0.1.2 → 0.1.3
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/isomer/sources/yaml.rb +4 -4
- data/lib/isomer/version.rb +1 -1
- data/spec/isomer/sources/yaml_spec.rb +41 -35
- metadata +3 -3
data/lib/isomer/sources/yaml.rb
CHANGED
@@ -16,13 +16,13 @@ class Isomer::Sources::Yaml < Isomer::Sources::Base
|
|
16
16
|
def load
|
17
17
|
if File.exists?(file)
|
18
18
|
values = YAML.load_file(file)
|
19
|
-
if
|
20
|
-
@configuration =
|
19
|
+
if !values.is_a?(Hash)
|
20
|
+
@configuration = {}
|
21
|
+
elsif base && values.has_key?(base)
|
22
|
+
@configuration = values[base] || {}
|
21
23
|
else
|
22
24
|
@configuration = values
|
23
25
|
end
|
24
|
-
|
25
|
-
@configuration ||= {}
|
26
26
|
else
|
27
27
|
raise Isomer::Error, "Missing required configuration file '#{file}'" if required
|
28
28
|
@configuration = {}
|
data/lib/isomer/version.rb
CHANGED
@@ -15,24 +15,52 @@ describe Isomer::Sources::Yaml do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#load' do
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
context 'when the file exists' do
|
19
|
+
context 'when the configuration values are a hash' do
|
20
|
+
it 'sets the configuration to the YAML file contents' do
|
21
|
+
File.stub(:exists?).and_return(true)
|
22
|
+
YAML.should_receive(:load_file).with('/home/configuration.yml').and_return({'foo' => 'bar'})
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
source = Isomer::Sources::Yaml.new(anything, file: '/home/configuration.yml')
|
25
|
+
source.load
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
source.configuration.should == {'foo' => 'bar'}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the configuration values are not a hash' do
|
32
|
+
it 'sets the configuration to an empty hash' do
|
33
|
+
File.stub(:exists?).and_return(true)
|
34
|
+
YAML.stub(:load_file).and_return('string value')
|
35
|
+
|
36
|
+
source = Isomer::Sources::Yaml.new(anything, file: 'anything.yml')
|
37
|
+
source.load
|
38
|
+
|
39
|
+
source.configuration.should == {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a base' do
|
44
|
+
it 'returns the configuration under the base node' do
|
45
|
+
File.stub(:exists?).and_return(true)
|
46
|
+
YAML.stub(:load_file).and_return( 'production' => {'limit' => 100} )
|
27
47
|
|
28
|
-
|
29
|
-
|
30
|
-
YAML.stub(:load_file).and_return(nil)
|
48
|
+
source = Isomer::Sources::Yaml.new(anything, file: 'filish.yml', base: 'production')
|
49
|
+
source.load
|
31
50
|
|
32
|
-
|
33
|
-
|
51
|
+
source.configuration.should == {'limit' => 100}
|
52
|
+
end
|
34
53
|
|
35
|
-
|
54
|
+
it 'returns an empty hash if the content is nil' do
|
55
|
+
File.stub(:exists?).and_return(true)
|
56
|
+
YAML.stub(:load_file).and_return( 'production' => nil )
|
57
|
+
|
58
|
+
source = Isomer::Sources::Yaml.new(anything, file: 'filish.yml', base: 'production')
|
59
|
+
source.load
|
60
|
+
|
61
|
+
source.configuration.should == {}
|
62
|
+
end
|
63
|
+
end
|
36
64
|
end
|
37
65
|
|
38
66
|
context 'when the file does not exist' do
|
@@ -58,27 +86,5 @@ describe Isomer::Sources::Yaml do
|
|
58
86
|
end
|
59
87
|
end
|
60
88
|
end
|
61
|
-
|
62
|
-
context 'with a base' do
|
63
|
-
it 'returns the configuration under the base node' do
|
64
|
-
File.stub(:exists?).and_return(true)
|
65
|
-
YAML.stub(:load_file).and_return( 'production' => {'limit' => 100} )
|
66
|
-
|
67
|
-
source = Isomer::Sources::Yaml.new(anything, file: 'filish.yml', base: 'production')
|
68
|
-
source.load
|
69
|
-
|
70
|
-
source.configuration.should == {'limit' => 100}
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns an empty hash if the content is nil' do
|
74
|
-
File.stub(:exists?).and_return(true)
|
75
|
-
YAML.stub(:load_file).and_return( 'production' => nil )
|
76
|
-
|
77
|
-
source = Isomer::Sources::Yaml.new(anything, file: 'filish.yml', base: 'production')
|
78
|
-
source.load
|
79
|
-
|
80
|
-
source.configuration.should == {}
|
81
|
-
end
|
82
|
-
end
|
83
89
|
end
|
84
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
segments:
|
109
109
|
- 0
|
110
|
-
hash:
|
110
|
+
hash: -2110743002867033305
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
none: false
|
113
113
|
requirements:
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: -2110743002867033305
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
122
|
rubygems_version: 1.8.25
|