ruby-changes:19913
From: tenderlove <ko1@a...>
Date: Thu, 9 Jun 2011 09:22:40 +0900 (JST)
Subject: [ruby-changes:19913] tenderlove:r31960 (trunk): * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby modules can be loaded
tenderlove 2011-06-09 09:22:33 +0900 (Thu, 09 Jun 2011) New Revision: 31960 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31960 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/to_ruby.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_class.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31959) +++ ChangeLog (revision 31960) @@ -1,3 +1,11 @@ +Thu Jun 9 09:18:51 2011 Aaron Patterson <aaron@t...> + + * 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@t...> * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31959) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31960) @@ -246,6 +246,11 @@ 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 Index: ext/psych/lib/psych/visitors/to_ruby.rb =================================================================== --- ext/psych/lib/psych/visitors/to_ruby.rb (revision 31959) +++ ext/psych/lib/psych/visitors/to_ruby.rb (revision 31960) @@ -57,7 +57,7 @@ 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)) Index: test/psych/test_class.rb =================================================================== --- test/psych/test_class.rb (revision 31959) +++ test/psych/test_class.rb (revision 31960) @@ -2,12 +2,21 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/