提交 52eedf5e 编写于 作者: J Jon Leighton

Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent...

Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent changes to attribute serialization.
上级 1c783c60
......@@ -1935,6 +1935,26 @@ def inspect
"#<#{self.class} #{inspection}>"
end
# Hackery to accomodate Syck. Remove for 4.0.
def to_yaml(opts = {}) #:nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
super
else
coder = {}
encode_with(coder)
YAML.quick_emit(self, opts) do |out|
out.map(taguri, to_yaml_style) do |map|
coder.each { |k, v| map.add(k, v) }
end
end
end
end
# Hackery to accomodate Syck. Remove for 4.0.
def yaml_initialize(tag, coder) #:nodoc:
init_with(coder)
end
protected
def clone_attributes(reader_method = :read_attribute, attributes = {})
attribute_names.each do |name|
......
......@@ -18,6 +18,11 @@ def test_roundtrip
assert_equal topic, t
end
def test_roundtrip_serialized_column
topic = Topic.new(:content => {:omg=>:lol})
assert_equal({:omg=>:lol}, YAML.load(YAML.dump(topic)).content)
end
def test_encode_with_coder
topic = Topic.first
coder = {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册