Class: Psych::Pure::Emitter::Visitor
- Inherits:
-
Object
- Object
- Psych::Pure::Emitter::Visitor
- Defined in:
- lib/psych/pure.rb
Overview
The visitor is responsible for walking the tree and generating the YAML output.
Instance Method Summary collapse
-
#initialize(q, sequence_indent: false) ⇒ Visitor
constructor
A new instance of Visitor.
-
#visit_alias(node) ⇒ Object
Visit an AliasNode.
-
#visit_array(node) ⇒ Object
Visit an ArrayNode.
-
#visit_hash(node) ⇒ Object
Visit a HashNode.
-
#visit_object(node) ⇒ Object
Visit an ObjectNode.
-
#visit_omap(node) ⇒ Object
Visit an OmapNode.
-
#visit_set(node) ⇒ Object
Visit a SetNode.
-
#visit_string(node) ⇒ Object
Visit a StringNode.
Constructor Details
#initialize(q, sequence_indent: false) ⇒ Visitor
4199 4200 4201 4202 |
# File 'lib/psych/pure.rb', line 4199 def initialize(q, sequence_indent: false) @q = q @sequence_indent = sequence_indent end |
Instance Method Details
#visit_alias(node) ⇒ Object
Visit an AliasNode.
4205 4206 4207 |
# File 'lib/psych/pure.rb', line 4205 def visit_alias(node) with_comments(node) { |value| @q.text("*#{value}") } end |
#visit_array(node) ⇒ Object
Visit an ArrayNode.
4210 4211 4212 4213 4214 4215 4216 4217 4218 |
# File 'lib/psych/pure.rb', line 4210 def visit_array(node) with_comments(node) do |value| if value.empty? || ((psych_node = node.psych_node).is_a?(Nodes::Sequence) && psych_node.style == Nodes::Sequence::FLOW && psych_node.children.any?) visit_array_contents_flow(node.anchor, node.tag, value) else visit_array_contents_block(node.anchor, node.tag, node.dirty, value) end end end |
#visit_hash(node) ⇒ Object
Visit a HashNode.
4221 4222 4223 4224 4225 4226 4227 4228 4229 |
# File 'lib/psych/pure.rb', line 4221 def visit_hash(node) with_comments(node) do |value| if value.empty? || ((psych_node = node.psych_node).is_a?(Nodes::Mapping) && psych_node.style == Nodes::Mapping::FLOW) visit_hash_contents_flow(node.anchor, node.tag, value) else visit_hash_contents_block(node.anchor, node.tag, value) end end end |
#visit_object(node) ⇒ Object
Visit an ObjectNode.
4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 |
# File 'lib/psych/pure.rb', line 4232 def visit_object(node) with_comments(node) do |value| if !node.dirty && (psych_node = node.psych_node) if (tag = node.tag) @q.text("#{tag} ") end @q.text(psych_node.source || psych_node.value) else if (tag = node.tag) && tag != "tag:yaml.org,2002:binary" @q.text("#{tag} ") end @q.text(dump_object(value)) end end end |
#visit_omap(node) ⇒ Object
Visit an OmapNode.
4251 4252 4253 4254 4255 |
# File 'lib/psych/pure.rb', line 4251 def visit_omap(node) with_comments(node) do |value| visit_array_contents_block(node.anchor, "!!omap", false, value) end end |
#visit_set(node) ⇒ Object
Visit a SetNode.
4258 4259 4260 4261 4262 |
# File 'lib/psych/pure.rb', line 4258 def visit_set(node) with_comments(node) do |value| visit_hash_contents_block(node.anchor, "!set", value) end end |
#visit_string(node) ⇒ Object
Visit a StringNode.
4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 |
# File 'lib/psych/pure.rb', line 4265 def visit_string(node) with_comments(node) do |value| if !node.dirty && (psych_node = node.psych_node) if (tag = node.tag) @q.text("#{tag} ") end @q.text(psych_node.source || psych_node.value) else if (tag = node.tag) && tag != "tag:yaml.org,2002:binary" @q.text("#{tag} ") end @q.text(dump_object(value)) end end end |