summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--NEWS3
-rw-r--r--lib/yaml.rb34
-rw-r--r--test/psych/test_engine_manager.rb47
-rw-r--r--test/psych/test_yamldbm.rb2
-rw-r--r--test/psych/test_yamlstore.rb2
6 files changed, 85 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 395eab5d31..bcbb418894 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,11 +16,6 @@ Sun May 25 11:56:33 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
start cannot exceed the size, the comparison was always false.
[ruby-core:62737] [Bug #9861]
-Sun May 25 11:32:42 2014 Zachary Scott <e@zzak.io>
-
- * lib/yaml.rb: Remove Psych::EngineManager [Bug #8344]
- * test/psych/*: ditto.
-
Sun May 25 10:34:15 2014 Zachary Scott <e@zzak.io>
* doc/regexp.rdoc: [DOC] Clarify whitespace matching by @allolex
diff --git a/NEWS b/NEWS
index 083cc9b3d8..f599cc2d7d 100644
--- a/NEWS
+++ b/NEWS
@@ -120,9 +120,6 @@ with all sufficient information, see the ChangeLog file.
* Prime.prime? now returns false for negative numbers. This method
should not be used to know the number is composite or not. [Bug #7395]
-* Psych
- * Removed Psych::EngineManager [Bug #8344]
-
=== Built-in global variables compatibility issues
=== C API updates
diff --git a/lib/yaml.rb b/lib/yaml.rb
index c0ffcf877b..3b4e4234f7 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -12,6 +12,40 @@ end
YAML = Psych # :nodoc:
+module Psych # :nodoc:
+ # For compatibility, deprecated
+ class EngineManager # :nodoc:
+ attr_reader :yamler # :nodoc:
+
+ def initialize # :nodoc:
+ @yamler = 'psych'
+ end
+
+ def syck? # :nodoc:
+ false
+ end
+
+ # Psych is always used and this method has no effect.
+ #
+ # This method is still present for compatibility.
+ #
+ # You may still use the Syck engine by installing
+ # the 'syck' gem and using the Syck constant.
+ def yamler= engine # :nodoc:
+ case engine
+ when 'syck' then warn "syck has been removed, psych is used instead"
+ when 'psych' then @yamler = 'psych'
+ else
+ raise(ArgumentError, "bad engine")
+ end
+
+ engine
+ end
+ end
+
+ ENGINE = EngineManager.new # :nodoc:
+end
+
# YAML Ain't Markup Language
#
# This module provides a Ruby interface for data serialization in YAML format.
diff --git a/test/psych/test_engine_manager.rb b/test/psych/test_engine_manager.rb
new file mode 100644
index 0000000000..33a67432eb
--- /dev/null
+++ b/test/psych/test_engine_manager.rb
@@ -0,0 +1,47 @@
+require_relative 'helper'
+require 'yaml'
+
+module Psych
+ class TestEngineManager < TestCase
+ def test_bad_engine
+ assert_raises(ArgumentError) do
+ YAML::ENGINE.yamler = 'foooo'
+ end
+ end
+
+ def test_set_psych
+ YAML::ENGINE.yamler = 'psych'
+ assert_equal Psych, YAML
+ assert_equal 'psych', YAML::ENGINE.yamler
+ end
+
+ A = Struct.new(:name)
+
+ def test_dump_types
+ YAML::ENGINE.yamler = 'psych'
+
+ assert_to_yaml ::Object.new
+ assert_to_yaml Time.now
+ assert_to_yaml Date.today
+ assert_to_yaml('a' => 'b')
+ assert_to_yaml A.new('foo')
+ assert_to_yaml %w{a b}
+ assert_to_yaml Exception.new('foo')
+ assert_to_yaml "hello!"
+ assert_to_yaml :fooo
+ assert_to_yaml(1..10)
+ assert_to_yaml(/hello!~/)
+ assert_to_yaml 1
+ assert_to_yaml 1.2
+ assert_to_yaml Rational(1, 2)
+ assert_to_yaml Complex(1, 2)
+ assert_to_yaml true
+ assert_to_yaml false
+ assert_to_yaml nil
+ end
+
+ def assert_to_yaml obj
+ assert obj.to_yaml, "#{obj.class} to_yaml works"
+ end
+ end
+end
diff --git a/test/psych/test_yamldbm.rb b/test/psych/test_yamldbm.rb
index 23c7c9e564..dba9eee2a9 100644
--- a/test/psych/test_yamldbm.rb
+++ b/test/psych/test_yamldbm.rb
@@ -13,6 +13,7 @@ module Psych
class YAMLDBMTest < TestCase
def setup
+ @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
@dir = Dir.mktmpdir("rubytest-file")
File.chown(-1, Process.gid, @dir)
@yamldbm_file = make_tmp_filename("yamldbm")
@@ -20,6 +21,7 @@ module Psych
end
def teardown
+ YAML::ENGINE.yamler = @engine
@yamldbm.clear
@yamldbm.close
FileUtils.remove_entry_secure @dir
diff --git a/test/psych/test_yamlstore.rb b/test/psych/test_yamlstore.rb
index 94f1330d37..19471b1e35 100644
--- a/test/psych/test_yamlstore.rb
+++ b/test/psych/test_yamlstore.rb
@@ -7,6 +7,7 @@ module Psych
class YAMLStoreTest < TestCase
def setup
+ @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
@dir = Dir.mktmpdir("rubytest-file")
File.chown(-1, Process.gid, @dir)
@yamlstore_file = make_tmp_filename("yamlstore")
@@ -14,6 +15,7 @@ module Psych
end
def teardown
+ YAML::ENGINE.yamler = @engine
FileUtils.remove_entry_secure @dir
end