Commit 6be535aa74f68f35c88109b32fd2038e9819721d
Exists in
master
Merge pull request #40 from craigmarksmith/master
Handle empty yaml files.
Showing
5 changed files
with
10 additions
and
1 deletions
Show diff stats
lib/settingslogic.rb
... | ... | @@ -111,7 +111,8 @@ class Settingslogic < Hash |
111 | 111 | when Hash |
112 | 112 | self.replace hash_or_file |
113 | 113 | else |
114 | - hash = YAML.load(ERB.new(open(hash_or_file).read).result).to_hash | |
114 | + file_contents = open(hash_or_file).read | |
115 | + hash = file_contents.empty? ? {} : YAML.load(ERB.new(file_contents).result).to_hash | |
115 | 116 | if self.class.namespace |
116 | 117 | hash = hash[self.class.namespace] or return missing_key("Missing setting '#{self.class.namespace}' in #{hash_or_file}") |
117 | 118 | end | ... | ... |
spec/settingslogic_spec.rb
... | ... | @@ -153,6 +153,10 @@ describe "Settingslogic" do |
153 | 153 | Settings.name.should == 'test' |
154 | 154 | end |
155 | 155 | |
156 | + it "should handle empty file" do | |
157 | + SettingsEmpty.keys.should eql([]) | |
158 | + end | |
159 | + | |
156 | 160 | # Put this test last or else call to .instance will load @instance, |
157 | 161 | # masking bugs. |
158 | 162 | it "should be a hash" do | ... | ... |