Permalink
Browse files

work around Ruby bug empty files in YAML.load_file

Ruby 1.9.3p194 includes a change to Psych to support BOM markers. Unfortunately, that change means that Psych will sometimes throw an exception when you try to call YAML.load_file on a file with zero bytes in it. This commit includes a workaround so that we don't call YAML.load_file if the config file is empty.
  • Loading branch information...
indirect committed May 24, 2012
1 parent b026bba commit 5799ae890752c1c2977e9fb232520a0806e063c2
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/bundler/settings.rb
View
@@ -2,8 +2,8 @@ module Bundler
class Settings
def initialize(root)
@root = root
- @local_config = (File.exist?(local_config_file) && yaml = YAML.load_file(local_config_file)) ? yaml : {}
- @global_config = (File.exist?(global_config_file) && yaml = YAML.load_file(global_config_file)) ? yaml : {}
+ @local_config = load_config(local_config_file)
+ @global_config = load_config(global_config_file)
end
def [](key)
@@ -111,5 +111,13 @@ def global_config_file
def local_config_file
Pathname.new("#{@root}/config")
end
+
+ def load_config(config_file)
+ if config_file.exist? && !config_file.size.zero?
+ yaml = YAML.load_file(config_file)
+ end
+ yaml || {}
+ end
+
end
end

0 comments on commit 5799ae8

Please sign in to comment.