Class: LineNumberHandler

Inherits:
Psych::TreeBuilder
  • Object
show all
Defined in:
lib/cfn-model/psych/handlers/line_number_handler.rb

Overview

We need to provide a handler that will add the line to the node as it is parsed. TreeBuilder is the “usual” handler, that creates the AST.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parserObject

The handler needs access to the parser in order to call mark



9
10
11
# File 'lib/cfn-model/psych/handlers/line_number_handler.rb', line 9

def parser
  @parser
end

Instance Method Details

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

We are only interested in scalars, so here we override the method so that it calls mark and adds the line info to the node.



14
15
16
17
18
19
# File 'lib/cfn-model/psych/handlers/line_number_handler.rb', line 14

def scalar value, anchor, tag, plain, quoted, style
  mark = parser.mark
  node = super
  node.line = mark.line
  node
end