diff options
author | Steve Richert <steve.richert@gmail.com> | 2013-09-05 20:13:33 -0400 |
---|---|---|
committer | Steve Richert <steve.richert@gmail.com> | 2013-11-26 19:20:38 -0500 |
commit | 536e0696b04f9b7a6c0fe67639ea44cc188498ac (patch) | |
tree | 57425832d12127d56b923c193a4cf34356385e1f | |
parent | b36cd3a8e8d87cd0b6681a750dcdf03fc2fddd20 (diff) | |
download | psych-536e0696b04f9b7a6c0fe67639ea44cc188498ac.zip |
Enable YAML serialization of Ruby delegators and simple delegators
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 2 | ||||
-rw-r--r-- | test/psych/visitors/test_yaml_tree.rb | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 1cb2137..677f5a6 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -171,6 +171,8 @@ module Psych @emitter.end_mapping end + alias :visit_Delegator :visit_Object + def visit_Struct o tag = ['!ruby/struct', o.class.name].compact.join(':') diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index 40702bc..65cc90e 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -3,6 +3,15 @@ require 'psych/helper' module Psych module Visitors class TestYAMLTree < TestCase + class TestDelegatorClass < Delegator + def initialize(obj); super; @obj = obj; end + def __setobj__(obj); @obj = obj; end + def __getobj__; @obj; end + end + + class TestSimpleDelegatorClass < SimpleDelegator + end + def setup super @v = Visitors::YAMLTree.create @@ -168,6 +177,14 @@ module Psych assert_cycle 'nUll' assert_cycle '~' end + + def test_delegator + assert_cycle(TestDelegatorClass.new([1, 2, 3])) + end + + def test_simple_delegator + assert_cycle(TestSimpleDelegatorClass.new([1, 2, 3])) + end end end end |