Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #40 from craigmarksmith/master

Handle empty yaml files.
  • Loading branch information...
commit 6be535aa74f68f35c88109b32fd2038e9819721d 2 parents 4884d45 + 2e1a1cd
@binarylogic authored
View
3  lib/settingslogic.rb
@@ -111,7 +111,8 @@ def initialize(hash_or_file = self.class.source, section = nil)
when Hash
self.replace hash_or_file
else
- hash = YAML.load(ERB.new(open(hash_or_file).read).result).to_hash
+ file_contents = open(hash_or_file).read
+ hash = file_contents.empty? ? {} : YAML.load(ERB.new(file_contents).result).to_hash
if self.class.namespace
hash = hash[self.class.namespace] or return missing_key("Missing setting '#{self.class.namespace}' in #{hash_or_file}")
end
View
3  spec/settings_empty.rb
@@ -0,0 +1,3 @@
+class SettingsEmpty < Settingslogic
+ source "#{File.dirname(__FILE__)}/settings_empty.yml"
+end
View
0  spec/settings_empty.yml
No changes.
View
4 spec/settingslogic_spec.rb
@@ -153,6 +153,10 @@ class NoSource < Settingslogic; end
Settings.name.should == 'test'
end
+ it "should handle empty file" do
+ SettingsEmpty.keys.should eql([])
+ end
+
# Put this test last or else call to .instance will load @instance,
# masking bugs.
it "should be a hash" do
View
1  spec/spec_helper.rb
@@ -6,6 +6,7 @@
require 'settings2'
require 'settings3'
require 'settings4'
+require 'settings_empty'
# Needed to test Settings3
Object.send :define_method, 'collides' do
Please sign in to comment.
Something went wrong with that request. Please try again.