summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych/coder.rb8
-rw-r--r--test/psych/test_coder.rb18
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/psych/coder.rb b/lib/psych/coder.rb
index ae88e4a..c9f9a18 100644
--- a/lib/psych/coder.rb
+++ b/lib/psych/coder.rb
@@ -25,12 +25,18 @@ module Psych
self.scalar = value
end
- # Emit a sequence with +value+ and +tag+
+ # Emit a sequence with +list+ and +tag+
def represent_seq tag, list
@tag = tag
self.seq = list
end
+ # Emit a sequence with +map+ and +tag+
+ def represent_map tag, map
+ @tag = tag
+ self.map = map
+ end
+
# Emit a scalar with +value+
def scalar= value
@type = :scalar
diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb
index 18f055e..eccf5ee 100644
--- a/test/psych/test_coder.rb
+++ b/test/psych/test_coder.rb
@@ -77,6 +77,24 @@ module Psych
end
end
+ class RepresentWithMap
+ yaml_tag name
+ attr_accessor :map
+
+ def init_with coder
+ @map = coder.map
+ end
+
+ def encode_with coder
+ coder.represent_map self.class.name, { 'a' => 'b' }
+ end
+ end
+
+ def test_represent_map
+ thing = Psych.load(Psych.dump(RepresentWithMap.new))
+ assert_equal({ 'a' => 'b' }, thing.map)
+ end
+
def test_represent_sequence
thing = Psych.load(Psych.dump(RepresentWithSeq.new))
assert_equal %w{ foo bar }, thing.seq