summaryrefslogtreecommitdiff
path: root/lib/bundler/psyched_yaml.rb
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2012-11-14 19:01:29 -0800
committerAndre Arko <andre@arko.net>2012-11-14 19:11:18 -0800
commit7268495a5a4708519fcfcfbe48940096672ea6a0 (patch)
tree9201c171cb9c8b2434d5ba8cff52aa5f3255d966 /lib/bundler/psyched_yaml.rb
parente89a18e408733ecb778940a5770167b91dbc48f6 (diff)
downloadbundler-7268495a5a4708519fcfcfbe48940096672ea6a0.tar.gz
refactor psyched_yaml
Diffstat (limited to 'lib/bundler/psyched_yaml.rb')
-rw-r--r--lib/bundler/psyched_yaml.rb30
1 files changed, 13 insertions, 17 deletions
diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb
index 9501d242df..fe1a701684 100644
--- a/lib/bundler/psyched_yaml.rb
+++ b/lib/bundler/psyched_yaml.rb
@@ -1,24 +1,20 @@
-# Psych could be a gem
begin
- gem 'psych'
-rescue Gem::LoadError
-end if defined?(Gem)
+ # Psych could be a gem, so set up the load path
+ gem 'psych' if defined?(gem)
-# Psych could be a stdlib
-begin
- # it's too late if Syck is already loaded
+ # Psych could just be in the stdlib
+ # but it's too late if Syck is already loaded
require 'psych' unless defined?(Syck)
rescue LoadError
+ # apparently Psych wasn't available. Oh well.
+ensure
+ # at least load the YAML stdlib, whatever that may be
+ require 'yaml'
end
-# Psych might NOT EXIST AT ALL
-require 'yaml'
-
-# if the file is not valid YAML:
-# * Syck raises ArgumentError
-# * Psych raises Psych::SyntaxError
-begin
- YamlSyntaxError = Psych::SyntaxError
-rescue NameError
- YamlSyntaxError = ArgumentError
+module Bundler
+ # On encountering invalid YAML,
+ # Psych raises Psych::SyntaxError
+ # Syck raises ArgumentError
+ YamlSyntaxError = defined?(Psych) ? Psych::SyntaxError : ArgumentError
end