summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 00:22:33 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 00:22:33 +0000
commitaaa52bf088d9f78d8e578ead12695a73639fc95a (patch)
tree74d4a45a080591f83ec34fc4e5050ffafd51d2d2
parenta8cc42d1ff3f3599a22d14a82fd046c71f719c2f (diff)
* ext/psych/lib/psych/visitors/to_ruby.rb: Ruby modules can be loaded
from YAML files. * ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby modules can be dumped to YAML files. * test/psych/test_class.rb: corresponding test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb2
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb5
-rw-r--r--test/psych/test_class.rb17
4 files changed, 31 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f0813f..d9e9cef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jun 9 09:18:51 2011 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby modules can be loaded
+ from YAML files.
+ * ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby modules can be
+ dumped to YAML files.
+ * test/psych/test_class.rb: corresponding test.
+
Thu Jun 9 09:05:04 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index cb0afd2..3f5be4d 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -57,7 +57,7 @@ module Psych
Complex(o.value)
when "!ruby/object:Rational"
Rational(o.value)
- when "!ruby/class"
+ when "!ruby/class", "!ruby/module"
resolve_class o.value
when "tag:yaml.org,2002:float", "!float"
Float(@ss.tokenize(o.value))
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index de35c76..4019859 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -246,6 +246,11 @@ module Psych
end
end
+ def visit_Module o
+ raise TypeError, "can't dump anonymous module: #{o}" unless o.name
+ @emitter.scalar o.name, nil, '!ruby/module', false, false, Nodes::Scalar::SINGLE_QUOTED
+ end
+
def visit_Class o
raise TypeError, "can't dump anonymous class: #{o}" unless o.name
@emitter.scalar o.name, nil, '!ruby/class', false, false, Nodes::Scalar::SINGLE_QUOTED
diff --git a/test/psych/test_class.rb b/test/psych/test_class.rb
index 8fd4ad0..156f2fb 100644
--- a/test/psych/test_class.rb
+++ b/test/psych/test_class.rb
@@ -2,12 +2,21 @@ require 'psych/helper'
module Psych
class TestClass < TestCase
+ module Foo
+ end
+
def test_cycle_anonymous_class
assert_raises(::TypeError) do
assert_cycle(Class.new)
end
end
+ def test_cycle_anonymous_module
+ assert_raises(::TypeError) do
+ assert_cycle(Module.new)
+ end
+ end
+
def test_cycle
assert_cycle(TestClass)
end
@@ -15,5 +24,13 @@ module Psych
def test_dump
Psych.dump TestClass
end
+
+ def test_cycle_module
+ assert_cycle(Foo)
+ end
+
+ def test_dump_module
+ Psych.dump Foo
+ end
end
end