Permalink
Browse files

adding module serialization support

  • Loading branch information...
tenderlove committed Jun 9, 2011
1 parent e28d3db commit 81a8408b358df3710b7ebdd76bec99aeea3580ed
Showing with 23 additions and 1 deletion.
  1. +1 −1 lib/psych/visitors/to_ruby.rb
  2. +5 −0 lib/psych/visitors/yaml_tree.rb
  3. +17 −0 test/psych/test_class.rb
@@ -57,7 +57,7 @@ def visit_Psych_Nodes_Scalar o
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))
@@ -246,6 +246,11 @@ def visit_String o
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
View
@@ -2,18 +2,35 @@
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
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

0 comments on commit 81a8408

Please sign in to comment.