Class: Psych::JSON::TreeBuilder

Inherits:
TreeBuilder show all
Defined in:
lib/psych/json/tree_builder.rb

Overview

Psych::JSON::TreeBuilder is an event based AST builder. Events are sent to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed.

Instance Attribute Summary

Attributes inherited from TreeBuilder

#root

Instance Method Summary collapse

Methods inherited from TreeBuilder

#alias, #end_stream, #initialize, #start_stream

Methods inherited from Handler

#alias, #empty, #end_mapping, #end_sequence, #end_stream, #start_stream, #streaming?

Constructor Details

This class inherits a constructor from Psych::TreeBuilder

Instance Method Details

#end_document(implicit_end = !streaming?) ⇒ Object



11
12
13
# File 'lib/psych/json/tree_builder.rb', line 11

def end_document implicit_end = !streaming?
  super(implicit_end)
end

#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/psych/json/tree_builder.rb', line 23

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

#start_document(version, tag_directives, implicit) ⇒ Object



7
8
9
# File 'lib/psych/json/tree_builder.rb', line 7

def start_document version, tag_directives, implicit
  super(version, tag_directives, !streaming?)
end

#start_mapping(anchor, tag, implicit, style) ⇒ Object



15
16
17
# File 'lib/psych/json/tree_builder.rb', line 15

def start_mapping anchor, tag, implicit, style
  super(anchor, tag, implicit, Nodes::Mapping::FLOW)
end

#start_sequence(anchor, tag, implicit, style) ⇒ Object



19
20
21
# File 'lib/psych/json/tree_builder.rb', line 19

def start_sequence anchor, tag, implicit, style
  super(anchor, tag, implicit, Nodes::Sequence::FLOW)
end