summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/json_tree.rb
blob: 0440dc778d35e7d23c04dda6ca2a2e62be94ccc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Psych
  module Visitors
    class JSONTree < YAMLTree
      def visit_Symbol o
        append create_scalar o.to_s
      end

      def visit_NilClass o
        scalar = Nodes::Scalar.new(
          'null', nil, nil, true, false, Nodes::Scalar::PLAIN)
        append scalar
      end

      private
      def create_document
        doc = super
        doc.implicit     = true
        doc.implicit_end = true
        doc
      end

      def create_mapping
        map = super
        map.style = Nodes::Mapping::FLOW
        map
      end

      def create_scalar value, anchor = nil, tag = nil, plain = false, quoted = true, style = Nodes::Scalar::ANY
        super(value, anchor, tag, false, true, style)
      end

      def create_sequence anchor = nil, tag = nil, implicit = true, style = Nodes::Sequence::FLOW
        super
      end
    end
  end
end