diff options
Diffstat (limited to 'ext/psych/lib/psych/json/stream.rb')
-rw-r--r-- | ext/psych/lib/psych/json/stream.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ext/psych/lib/psych/json/stream.rb b/ext/psych/lib/psych/json/stream.rb new file mode 100644 index 0000000000..a6da584cbf --- /dev/null +++ b/ext/psych/lib/psych/json/stream.rb @@ -0,0 +1,32 @@ +module Psych + module JSON + class Stream < Psych::Stream + class Emitter < Psych::Stream::Emitter # :nodoc: + def start_document version, tag_directives, implicit + super(version, tag_directives, !streaming?) + end + + def start_mapping anchor, tag, implicit, style + super(anchor, tag, implicit, Nodes::Mapping::FLOW) + end + + def start_sequence anchor, tag, implicit, style + super(anchor, tag, implicit, Nodes::Sequence::FLOW) + end + + def scalar value, anchor, tag, plain, quoted, style + if "tag:yaml.org,2002:null" == tag + super('null', nil, nil, true, false, Nodes::Scalar::PLAIN) + else + super + end + end + end + + def visit_String o + @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::ANY + end + alias :visit_Symbol :visit_String + end + end +end |