diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-22 17:43:16 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-22 17:43:16 +0000 |
commit | 5571c7315e118b339c6b6590e666dfda68a7327d (patch) | |
tree | fcff1492ba18c09a44d2d29431e320591e0ac9c1 /lib/yaml.rb | |
parent | b8910f3751e985d04c2049be3c23c2ef5a9d9ecc (diff) | |
download | ruby-5571c7315e118b339c6b6590e666dfda68a7327d.tar.gz |
* ext/syck: removed. Fixes [ruby-core:43360]
* test/syck: removed.
* lib/yaml.rb: only require psych, show a warning if people try to set
the engine to syck.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml.rb')
-rw-r--r-- | lib/yaml.rb | 74 |
1 files changed, 20 insertions, 54 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb index 6ae71fb1dc..19df5efc53 100644 --- a/lib/yaml.rb +++ b/lib/yaml.rb @@ -2,75 +2,41 @@ # The YAML module allows you to use one of the two YAML engines that ship with # ruby. By default Psych is used but the old and unmaintained Syck may be # chosen. -# -# See Psych or Syck for usage and documentation. -# -# To set the YAML engine to syck: -# -# YAML::ENGINE.yamler = 'syck' -# -# To set the YAML engine back to psych: -# -# YAML::ENGINE.yamler = 'psych' -module YAML +begin + require 'psych' +rescue LoadError + warn "#{caller[0]}:" + warn "It seems your ruby installation is missing psych (for YAML output)." + warn "To eliminate this warning, please install libyaml and reinstall your ruby." + raise +end + +module Psych class EngineManager # :nodoc: attr_reader :yamler def initialize - @yamler = nil + @yamler = 'psych' end def syck? - 'syck' == @yamler + false end def yamler= engine - raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine) - - require engine unless (engine == 'syck' ? Syck : Psych).const_defined?(:VERSION) + case engine + when 'syck' then warn "syck has been removed" + when 'psych' then @yamler = 'psych' + else + raise(ArgumentError, "bad engine") + end - ::Object.class_eval <<-eorb, __FILE__, __LINE__ + 1 - remove_const 'YAML' - YAML = #{engine.capitalize} - remove_method :to_yaml - alias :to_yaml :#{engine}_to_yaml - eorb - - @yamler = engine engine end end - ## - # Allows changing the current YAML engine. See YAML for details. - - ENGINE = YAML::EngineManager.new -end - -if defined?(Psych) - engine = 'psych' -elsif defined?(Syck) - engine = 'syck' -else - begin - require 'psych' - engine = 'psych' - rescue LoadError - warn "#{caller[0]}:" - warn "It seems your ruby installation is missing psych (for YAML output)." - warn "To eliminate this warning, please install libyaml and reinstall your ruby." - require 'syck' - engine = 'syck' - end -end - -module Syck - ENGINE = YAML::ENGINE -end - -module Psych - ENGINE = YAML::ENGINE + ENGINE = EngineManager.new # :nodoc: end -YAML::ENGINE.yamler = engine +YAML = Psych |