Class: Psych::Visitors::ToRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/brujula/yaml_parser.rb

Instance Method Summary collapse

Instance Method Details

#revive_hash(hash, o) ⇒ Object



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
38
# File 'lib/brujula/yaml_parser.rb', line 12

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

    # TODO
    # This is not working because instead of returning a `val`, which could
    # be an string for example, it's returning a hash
    # Actually, I am not really interested in adding the line number to
    # object values. I am only interested in adding the lines to the object
    # itself, probably, as some kind of raml anotation, so it could be used
    # as another anotated property, and thus, displayed in the documentation
    # TODO

    if v.is_a? ::Psych::Nodes::Scalar
      val = { "value" => val, "_brujula_line" => v._brujula_line + 1} # line is 0 based, so + 1
    end

    # Code dealing with << (for merging hashes) omitted.
    # If you need this you will probably need to copy it
    # in here. See the method:
    # https://github.com/tenderlove/psych/blob/v2.0.13/lib/psych/visitors/to_ruby.rb#L333-L365

    hash[key] = val
  }
  hash
end