diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-09-17 13:47:48 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-09-17 14:51:16 -0600 |
commit | 2a4d9568f7d5d19c00231cf48eb855cc45ec3394 (patch) | |
tree | b243635b09994bdce41482912635f18d83064a18 /lib/psych/visitors/yaml_tree.rb | |
parent | 29d4544ff07dbb51421c7fab6e8bd54baecc78c0 (diff) | |
download | psych-2a4d9568f7d5d19c00231cf48eb855cc45ec3394.zip |
Allow dumping any BasicObject that defines #marshal_dump or #marshal_load
Additionally, it is assumed that these objects will have implemented
`respond_to?` and `class`, (e.g. SimpleDelegator). These assumptions are
reasonably inline with the assumptions of `Marshal` in regards to
`BasicObject`s.
Diffstat (limited to 'lib/psych/visitors/yaml_tree.rb')
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 3f2427b..989e1f0 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -27,6 +27,8 @@ module Psych def key? target @obj_to_node.key? target.object_id + rescue NoMethodError + false end def id_for target @@ -411,6 +413,18 @@ module Psych end end + def visit_BasicObject o + tag = Psych.dump_tags[o.class] + tag ||= "!ruby/marshalable:#{o.class.name}" + + map = @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK) + register(o, map) + + o.marshal_dump.each(&method(:accept)) + + @emitter.end_mapping + end + private # FIXME: Remove the index and count checks in Psych 3.0 NULL = "\x00" |