summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-02-28 18:10:39 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-02-28 18:10:39 -0800
commit960d30ef5ac4ab93db199852fcd93f3cc3dfe1dd (patch)
treec994e1379c146c60716d59fedd8db8f7f7342723
parent5e6a486f3c0cde1529e47e4b74816284414762a4 (diff)
downloadpsych-960d30ef5ac4ab93db199852fcd93f3cc3dfe1dd.zip
* ext/psych/lib/psych/visitors/yaml_tree.rb: support dumping Encoding
objects. * ext/psych/lib/psych/visitors/to_ruby.rb: support loading Encoding objects. * test/psych/test_encoding.rb: add test * ext/psych/lib/psych.rb: add version
-rw-r--r--CHANGELOG.rdoc12
-rw-r--r--lib/psych/visitors/to_ruby.rb2
-rw-r--r--lib/psych/visitors/yaml_tree.rb5
-rw-r--r--test/psych/test_encoding.rb5
4 files changed, 24 insertions, 0 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index eeeb893..c964089 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,3 +1,15 @@
+Sat Mar 1 11:08:00 2014 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/yaml_tree.rb: support dumping Encoding
+ objects.
+
+ * ext/psych/lib/psych/visitors/to_ruby.rb: support loading Encoding
+ objects.
+
+ * test/psych/test_encoding.rb: add test
+
+ * ext/psych/lib/psych.rb: add version
+
Wed Feb 5 10:11:36 2014 Zachary Scott <e@zzak.io>
* ext/psych/yaml/config.h: bump libyaml to 0.1.5
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 42b328a..2f84b10 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -75,6 +75,8 @@ module Psych
class_loader.date_time
require 'date'
@ss.parse_time(o.value).to_datetime
+ when '!ruby/encoding'
+ ::Encoding.find o.value
when "!ruby/object:Complex"
class_loader.complex
Complex(o.value)
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index f89fcbb..ff0fcd2 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -157,6 +157,11 @@ module Psych
@emitter.end_sequence
end
+ def visit_Encoding o
+ tag = "!ruby/encoding"
+ @emitter.scalar o.name, nil, tag, false, false, Nodes::Scalar::ANY
+ end
+
def visit_Object o
tag = Psych.dump_tags[o.class]
unless tag
diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb
index e370606..517cae2 100644
--- a/test/psych/test_encoding.rb
+++ b/test/psych/test_encoding.rb
@@ -31,6 +31,11 @@ module Psych
@emitter = Psych::Emitter.new @buffer
end
+ def test_dump_load_encoding_object
+ assert_cycle Encoding::US_ASCII
+ assert_cycle Encoding::UTF_8
+ end
+
def test_transcode_shiftjis
str = "こんにちは!"
loaded = Psych.load("--- こんにちは!".encode('SHIFT_JIS'))