Class: ToRubyWithLineNumbers

Inherits:
Psych::Visitors::ToRuby
  • Object
show all
Defined in:
lib/cfn-model/psych/visitors/to_ruby_with_line_numbers.rb

Instance Method Summary collapse

Instance Method Details

#revive_hash(hash, o) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cfn-model/psych/visitors/to_ruby_with_line_numbers.rb', line 2

def revive_hash hash, o
  o.children.each_slice(2) { |k,v|
    key = accept(k)
    val = accept(v)

    # Supporting various versions of psych
    line = v.respond_to?(:start_line) ? v.start_line + 1 : v.line

    # This is the important bit. If the value is a scalar,
    # we replace it with the desired hash.
    if v.is_a?(::Psych::Nodes::Scalar) && key == 'Type'
      val = { "value" => val, "line" => line}
    end

    hash[key] = val
  }
  hash
end